we can run command via ssh:
$ ssh user@host bash -c "'echo x '"
x
However I found that I cannot escape '
:
$ ssh user@host bash -c "'echo \''"
bash: -c: line 0: unexpected EOF while looking for matching `''
bash: -c: line 1: syntax error: unexpected end of file
I also tried \\
and \\\
, \\\\
, nothing works.
the idea is to pass things like ls -1tr /var/log/ | head -10 | xargs -d '\n' -I {} echo {}
. But the \'
does not work so I do not know how to pass the '\n'
. How can I achieve this?
foo'bar
use'foo'\''bar'
. You might have to double the backslashes. Try"'ls -1tr /var/log/ | head -10 | xargs -d '\\''\\n'\\'' -I {} echo {}'"
. – Bodo Feb 12 '21 at 15:25