Similar to my question here, except with multiple ssh, and similar to this question but with white space in the arguments...
I would like to run a local script, test.sh, on a remote server via multiple ssh. test.sh takes an argument that often has multiple words.
test.sh:
#!/bin/bash
while getopts b: opt;
do
case $opt in
b)
bval="$OPTARG"
;;
esac
done
echo $bval
call_test.sh
#!/bin/bash
# Do some stuff
PHRASE="multi word arg"
ssh -A user@host1 "bash -s" -- < ./test.sh -b "${PHRASE@Q}"
and run ./call_test.sh, this correctly outputs
multi word arg
But when I change the last line of call_test.sh to the following:
ssh -A user@host1 ssh -A user@host2 "bash -s" -- < ./test.sh -b "${PHRASE@Q}"
and run ./call_test.sh, it outputs:
multi
Basically, changing from single SSH to multiple SSH breaks my multi-word argument.
I think that the multiple ssh commands are unwrapping the quotes for the multi-word argument at each step, but I'm not sure how to prevent that. Any ideas how to successfully pass the multi-word argument to the script running across multiple ssh?
Edit:
I believe this answer gets at the problem that I'm running into.