file.tmp" With two enclo...">

Nested quotes of bash

I want to nest a few lines as follows:

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

With two enclosed quotes, I managed to execute my command:

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

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

Thanks in advance.

+8
string bash shell command nested
source share
1 answer

You can put single quotes as long as the variables are intended for the initial extension before the entire command line is run in the shell on the remote server.

 sudo ssh server "echo \"$SOMEVAR\"; awk '/pattern/{print \"hello\"}1' file > file.tmp" 
+11
source share

All Articles