不同的bashpathvariables使用ssh脚本vs交互式ssh

我试图通过脚本使用Plink运行一些ruby(bundler / rvm)命令。 我注意到这是抱怨不知道某些命令在哪里。 看起来好像我的$PATHvariables不同于我使用交互式shell的时候,以及当我用Plink指定一个命令文件的时候。

在我的.bash_profile我有这个:

 [[ -s "$HOME/.profile" ]] && source "$HOME/.profile" # Load the default .profile [[ -s "$HOME/.rvm/scripts/rvm" ]] && source "$HOME/.rvm/scripts/rvm" # Load RVM into a shell session *as a function* 

如果我理解正确,当不在交互模式时,应该读取.bashrc而不是.bash_profile 。 所以,如果这是正确的,这是我的.bashrc的最后一行:

 export PATH="$PATH:$HOME/.rvm/bin" # Add RVM to PATH for scripting 

那会告诉我,我应该在我的道路上看到,但我不知道。 这是我得到我的$PATH

 /usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games 

这看起来像我默认的$PATHvariables。 为什么当我尝试通过ssh运行命令时,我的.bashrc不会被find?

我已经添加echo "the bashrc has been called"我的.bashrc 。 我从来没有看到,当我运行我的脚本。

有三种可能的情况:

  1. 交互式loginshell:读取~/.bash_profile~/.bash_login~/.profile
  2. 交互式不loginshell:读取~/.bashrc
  3. 不交互式:读取包含在variablesBASH_ENV的文件,如果存在的话。

看起来你正在陷入第三个案子。 例如,你可以在一个文件中设置你想要的PATH: ~/.ssh/environment或者你可以在同一个文件中设置BASH_ENV指向~/.bashrc