Tramp使用ssh时没有读取.bash_profile/.profile文件

10

我正在使用Aquamacs(OSX上的图形化emacs,使用emacs 24和tramp版本2.2.3)编辑远程服务器上的一些文件。 Tramp设置为使用ssh,在编辑文件方面运作良好。

当进行编译时失败,因为编译器不在路径中。似乎tramp没有使用任何配置文件,如.profile.bash_profile。 /bin/sh是指向/bin/bash的链接,因此bash应该是tramp使用的shell。在远程服务器上启动的shell也不会读取任何内容。 从常规终端模拟器(在OS X上尝试了终端X11)的ssh连接按预期工作(正确地读取所有内容)。

有什么想法吗?


一个相关问题在http://emacs.stackexchange.com上:[如何让tramp+eshell使用我在远程~/.bash_profile中自定义的环境](http://emacs.stackexchange.com/q/7673/5165)。 - imz -- Ivan Zakharyaschev
2个回答

5
/bin/sh是指向/bin/bash的链接,因此tramp应使用bash作为shell。
然而,它们并不完全相同。当以"sh"形式调用时,它将表现得像sh而不是bash,因此bash特定的rc/profile文件(例如~/.bash_profile、~/.bashrc)不会被引用。但是~/.profile将被读取。您的问题可能是在~/.profile中使用bash语法设置内容。
以下设置将不起作用:
export PATH=/some/path:$PATH

但是这将会:
PATH=/some/path:$PATH
export PATH

8
在我的情况下,.profile 文件被完全忽略了。当手动调用 /bin/sh 时重新加载它确实会得到正确的路径,但就其自身而言,tramp 似乎不会载入 ~/.profile 文件。 - Julian
1
我不确定将export PATH放在~/.profile~/.bash_profile的单独一行是否能让tramp理解它,但我尝试以类似的方式设置EDITOR被tramp设置,但无论是在~/.profile还是~/.bash_profile中都没有起作用,所以最终我通过tramp-remote-process-environment再次设置它,就像我在https://emacs.stackexchange.com/a/7685/5165中所说的那样。这并不完全方便,因为不同的远程主机可能需要不同的值。 - imz -- Ivan Zakharyaschev

3
我曾经遇到过这个问题,从我的shell历史记录中可以看到,tramp作为非登录shell执行了/bin/sh,这意味着~/.profile不会被执行。
这听起来像是Emacs手册这里所说的。

Another way to find the remote path is to use the path assigned to the remote user by the remote host. Tramp does not normally retain this remote path after login. However, tramp-own-remote-path preserves the path value, which can be used to update tramp-remote-path.

      (add-to-list 'tramp-remote-path 'tramp-own-remote-path)

Note that this works only if your remote /bin/sh shell supports the login argument ‘-l’.

按照描述,将'tramp-own-remote-path'添加到tramp-remote-path中后,我在命令历史记录中看到了添加了-l标志的命令,并且像预期的那样源化了~/.profile

(这是在接受的答案中描述的,该答案链接到伊万的评论,但它没有提到通过源化~/.profile来遵守PATH的规则,这意味着可以在该文件中进行其他环境自定义。)


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接