So I have been running local scripts fine on a remote server:
ssh user@server "`cat local-script.sh`"
However, today I have a script that has both single and double quotes in it. Which causes the script to fail because the output of cat local-script.sh
is wrapped in quotes. With out modifying the script itself, is there a better way to handle this?
I thought this may work:
ssh user@server $(<local-script.sh)
But is does not seem to do anything...
or whatever shell you want to use instead of bash
With the following test script:
The output should be the remote host name followed by 4 and 3 when executed using:
This shows that the quotes inside the script are being handled correctly. If the quotes weren't being handled correctly, the numbers output would be 5 and 4 due to word splitting. Note the quotes around the command substitution.
By the way, the first command you posted doesn't work. The single quotes prevent the backticks from being evaluated locally.
Assume that the script is in file script.sh. What the heck is the problem with running:
This works for me!