Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Bash nested quotes and eval

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
like image 234
Zeophlite Avatar asked Mar 01 '12 03:03

Zeophlite


People also ask

How do you quote within a quote in bash?

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.

How can I escape a double quote inside double quotes?

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 ' !

How do you pass a double quote into a string in a shell script?

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: " ==> \", \ ==> \\

How do you escape a single quote within a single quote?

' End first quotation which uses single quotes. " Start second quotation, using double-quotes. ' Quoted character. " End second quotation, using double-quotes.


1 Answers

Use an array instead.

#!/bin/bash
cmd=(echo "foo bar")
"${cmd[@]}"
like image 148
Ignacio Vazquez-Abrams Avatar answered Sep 25 '22 06:09

Ignacio Vazquez-Abrams