0

When I ssh into host and echo $PATH:

$ ssh my@host
$ echo $PATH

I get a different value for $PATH than when I run a script locally:

ssh my@host '\
    echo $PATH;'

Any idea why?

NOTE: It seems I don't get the full path variable when sshing from a script versus [other] CLI.

slm
  • 369,824
the_prole
  • 457

2 Answers2

0

Adding this line to bash script worked

source ~/.bash_profile

source

slm
  • 369,824
the_prole
  • 457
0

This is due to the fact that when you run a command through ssh (ssh user@host 'command') it opens a non-login shell. An excellent breakdown of the differences between a login shell and a non-login shell can be found at this question. Essentially, what is causing you issue is that when you run the command through ssh your ~/.bash_profile is not sourced, meaning any modifications to the path it makes will not be available.

The solution is to either move these into your ~/.bashrc, which is sourced on opening a non-login shell, or as you found out, sourcing your .bash_profile directly in the script.

Thegs
  • 686