why the command

ssh user@host echo $PATH


ssh user@host -t echo $PATH

return me the path on the local machine and not the path on the remote one?

This means that executing a remote command like

ssh user@host command

will search for this command on remote machine but using the path defined on the local machine, it's a bit strange behaviour or am I wrong?

  • 3
    Your local shell is expanding $PATH before it even runs ssh. Try quoting it.
    – Mikel
    Commented Oct 20, 2019 at 14:17
  • it's the same here. I asked this because I was running a command on a remote machine and it didn't find it even it it was on path (remote machine) and then I find this strange behaviour testing it in this way
    – res1
    Commented Oct 20, 2019 at 14:19
  • Don’t forget to use ‘single quotes’. Most shells interpolate variables if you use “double quotes”. (Quotes used here as demonstration, not for emphasis or sarcasm)
    – jsbillings
    Commented Oct 20, 2019 at 14:44
  • 2
    Possible duplicate of ssh: execute command on the remote host instead of a login shell
    – Wieland
    Commented Oct 20, 2019 at 15:07

1 Answer 1


The command

ssh user@host echo $PATH

would execute echo on the remote host with whatever the value of $PATH is locally since the variable is given on the command line unquoted.

To get the remote path, make sure that the local shell does not expand the variable:

ssh user@host 'echo $PATH'

The single quotes around the command stops the local shell from expanding $PATH.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .