Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

What is the correct way of quoting named arguments in bash?

In bash I can use named arguments like this:

command --argument=value

What is the correct way of quoting them if I need to include spaces?

command --argument="long value"
or
command "--argument=long value"

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

What is the correct way of quoting them if I need to include spaces?

Any quoting that does the job – preserves the space that you want to preserve – is fine. Any of these run the same command:

echo cmd --argument="long value"
echo cmd "--argument=long value"
echo cmd --argument=long\ value
echo cmd --argument=long' 'value
echo cmd --argument=long" "value
echo cmd --argument=long" value"
echo cmd --argument=l'ong 'value
echo cmd '--argument=long value'
echo cmd '''--argument=long value'''   # same as above, with empty '' pairs
echo cmd '-'-'a'r'g'u'm'e'n't'='l'o'n'g v'a'l'u'e'  # just having fun

You can check if your quoting is fine with set -x and inspecting the output.

$ set -x
$ echo cmd --argument="long value"
+ echo cmd '--argument=long value'
$ echo cmd "--argument=long value"
+ echo cmd '--argument=long value'
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading