FuSsA
FuSsA

Reputation: 4297

Remote SSH : no such file or directory

When trying to run this cmd:

ssh user@host " cp -f /path1/`cat /path2/file.txt | awk -F : '{printf $4}' `* ../ "

got this:

cat: /path2/file.txt: no such file or directory

Notice that when execute it directly in the server it works

Thanks for any advice

Upvotes: 1

Views: 7752

Answers (1)

ceving
ceving

Reputation: 23871

Try this:

ssh user@host 'cp -f /path1/$(awk -F : '\''{printf $4}'\'' /path2/file.txt)* ..'

This might be also interesting: Useless Use of Cat Award.

Or this:

ssh user@host 'cp -f '\'"$path1"\''/$(awk -F : '\''{printf $4}'\'' /path2/file.txt)* ..'

Keep in mind:

  • Singe quotes do not evaluate $.
  • Double quotes do evaluate $.
  • If you want to put a single quote into a single quoted string, you have to split the string in two parts and put an escaped single quote in between. 'a'\''b' becomes a'b
  • If you need to evaluate a variable in a single quoted string, you have to split the string in two parts and put the double quoted variable in between. 'a'"$x"'b' becomes a${x}b

Upvotes: 4

Related Questions