Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Nested quotes bash [duplicate]

I want to nest multiple strings like this :

sudo ssh server "awk "/pattern/{print "hello"}1" file > file.tmp"

With 2 nested quotes I managed to make my command works :

awk "/pattern/{print \"hello\"}1" file > file.tmp

I cannot use single quote (') because there are variables in my command. Can someone help me ?

Thanks in advance.

like image 832
BDR Avatar asked Sep 18 '13 19:09

BDR


1 Answers

You can still place single quotes as long as the variables are intended to be initially expanded before the whole command string is executed on the shell on the remote server.

sudo ssh server "echo \"$SOMEVAR\"; awk '/pattern/{print \"hello\"}1' file > file.tmp"
like image 149
konsolebox Avatar answered Nov 05 '22 12:11

konsolebox