I want to run a program on a machine that I have ssh access to from a gateway machine that I can access with ssh too.When I want to run an mpi program on the target machine T, I access to the gateway G from my local machine the usual way :ssh user@GatewayOnce on the G machine, I start my program on the target machine like this :ssh Target 'eval $(ssh-agent -s);ssh-add my_key;mpirun --hostfile .hosts program'This way everything works correctly (notice that I need ssh-agent and ssh-add to run before mpirun, refer to this question for details.)I want to pass the second ssh command directly to the ssh command on my local machine when I access the Gateway, something like thisssh user@Gateway ssh Target 'eval $(ssh-agent -s);ssh-add my_key;mpirun --hostfile .hosts program'But this doesn't work, because of the  I think.PS: I cannot use ssh-agent-forwarding.
Run ssh as a command of another ssh command
ssh;remote;quoting
You have the escape the $. Otherwise $(ssh-agent -s) will get evaluated on your local machine instead of the gateway machine.ssh user@Gateway ssh Target 'eval \$(ssh-agent -s);ssh-add my_key;mpirun --hostfile .hosts program'You can verify the results of escaping by using echo$ echo foo $(echo bar)foo bar$ echo foo \$(echo bar)foo $(echo bar)