Do it this way instead:
function mycommand {
ssh [email protected] "cd testdir;./test.sh \"$1\""
}
You still have to pass the whole command as a single string, yet in that single string you need to have $1
expanded before it is sent to ssh so you need to use ""
for it.
Another proper way to do this actually is to use printf %q
to properly quote the argument. This would make the argument safe to parse even if it has spaces, single quotes, double quotes, or any other character that may have a special meaning to the shell:
function mycommand {
printf -v __ %q "$1"
ssh [email protected] "cd testdir;./test.sh $__"
}
function
, ()
is not necessary.