Assume I have a script with the following contents located at ~/echo.sh
on a remote server example.com
:
#!/usr/bin/env bash
echo "Arg 1: $1"
echo "Arg 2: $2"
echo "Arg 3: $3"
echo "Arg 4: $4"
Now, on my local machine, I have another script, remote-echo.sh
with the following contents:
#!/usr/bin/env bash
ssh example.com "~/echo.sh $*"
The idea is that a user should be able to run remote-echo.sh
with any arguments and have those arguments be forwarded to ~/echo.sh
on the remote server.
Unfortunately, this doesn't work:
$ ./remote-echo.sh "arg with space" "argwith\"quote" "arg3"
bash: -c: line 0: unexpected EOF while looking for matching `"'
bash: -c: line 1: syntax error: unexpected end of file
How do I fix this? I already tried using $@
instead of $*
, but that didn't have any effect on the result at all.