I'm having difficulty nested quotes within a bash script
argv="su -c '$RVM_PATH wrapper $config_rvm \'$PASSENGER_RVM_BIN $command $options\'' web"
eval $argv
The above got me
eval: line 162: unexpected EOF while looking for matching `''
eval: line 163: syntax error: unexpected end of file
Sometimes it is required to print a single quote inside a string. A single quoted string can't contain another single quote inside the string. You can do this task by adding backslash in the front of single quote. In the following example, single quote of don't word is printed by using backslash.
A double quote may be quoted within double quotes by preceding it with a backslash. If enabled, history expansion will be performed unless an ' ! ' appearing in double quotes is escaped using a backslash. The backslash preceding the ' !
To quote a generic string with double quotes, perform the following actions: Add leading and trailing double quotes: aaa ==> "aaa" Escape with a backslash every double quote character and every backslash character: " ==> \", \ ==> \\
' End first quotation which uses single quotes. " Start second quotation, using double-quotes. ' Quoted character. " End second quotation, using double-quotes.
Use an array instead.
#!/bin/bash
cmd=(echo "foo bar")
"${cmd[@]}"
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With