Paolovip
Paolovip

Reputation: 133

Proper use of quotation marks for executing command using SSH

I need help with bash quotations rules:

I know I can run such a command:

/usr/bin/ssh root@my_srv "ls /usr/local/bin"

But I'm lost when I need a more complex commands, like this one that don't works, for example:

/usr/bin/ssh root@my_srv "awk '/dbname/{print $NF}' /var/myfile | sed "s/'//g" | sed 's/,//g'"

The same command launched directly in the remote server works fine:

awk '/dbname/{print $NF}' /var/myfile | sed "s/'//g" | sed 's/,//g'

Upvotes: 0

Views: 213

Answers (2)

sungtm
sungtm

Reputation: 577

After SSH login command, script or command may also be written directly without double quotes.

Upvotes: 0

jacalvo
jacalvo

Reputation: 666

You need to escape the inner double quotes with \ like this:

"awk '/dbname/{print \$NF}' /var/myfile | sed \"s/'//g\" | sed 's/,//g'"

Upvotes: 1

Related Questions