Issue
I am using
ssh -t <remote-host> bash -ic run_it 100
where run_it is defined like:
run_it() { echo Hello $1 }
On the remote machine it runs fine.
Arguments not getting passed when run using ssh.
Any help appreciated.
Solution
As another, now deleted, answer pointed out, when you use bash -c
, the command to run is the next single argument, and the one after, if any, is a string to use as $0
. Subsequent ones are interpreted as positional parameters for the shell, but that does not help you because for your purposes, you need arguments for the command inside the shell.
The best approach is probably to quote the command you want run in the shell. I find, however, that I need to double quote it:
ssh -t <remote-host> bash -ic "'run_it 100'"
One level of quotes will be removed by the local shell in which you execute the command. The fact that you need (or I do, anyway) the additional quotes seems to indicate that the specified command is being run on the remote side via a shell, rather than directly. I do not find that detail documented, and it's not what I expected, but there you have it.
Answered By - John Bollinger Answer Checked By - Dawn Plyler (WPSolving Volunteer)