Executing command remotely with ssh, and PATH

Tony Arnold tony.arnold at manchester.ac.uk
Thu Aug 9 13:47:32 UTC 2012


Colin,

On 09/08/12 14:42, Colin Law wrote:
> There is apparently something I am not understanding about ssh or
> environment variables.  I can execute a command remotely using ssh,
> something like
> ssh remote_server "command_to_execute"
> and that works ok.  However in another case I need to add to the path
> before executing the command so I to test the concept I tried
> ssh remote_server "PATH=/some/path:$PATH; echo $PATH"
> but it just shows the original path.  If I login to the remote server
> and copy/paste the above command then it shows the extended path as
> expected.

That's because the variable substituion of $PATH is happening on the
local machine before the command is sent to the remote machine. Try
escaping the dollar signs with \$ and see if that fixes it.

Regards,
Tony.

-- 
Tony Arnold,                        Tel: +44 (0) 161 275 6093
Head of IT Security,                Fax: +44 (0) 705 344 3082
University of Manchester,           Mob: +44 (0) 773 330 0039
Manchester M13 9PL.                 Email: tony.arnold at manchester.ac.uk




More information about the ubuntu-users mailing list