【问题标题】:Tramp using ssh does not source .bash_profile / .profileTramp 使用 ssh 不来源 .bash_profile / .profile
【发布时间】:2012-05-14 20:14:43
【问题描述】:

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

编译失败,因为编译器不在路径中。似乎 tramp 没有获取任何配置文件,如 .profile.bash_profile。 /bin/sh 是指向 /bin/bash 的链接,因此 bash 应该是 tramp 使用的 shell。在远程服务器上的 emacs 中启动的 shell 也不会获取任何内容。 来自常规终端仿真器(在 OS X 上尝试过 TerminalX11)的 ssh 连接按预期工作(一切来源正确)。

有什么想法吗?

【问题讨论】:

标签: bash emacs aquamacs tramp


【解决方案1】:

/bin/sh 是指向 /bin/bash 的链接,因此 bash 应该是 流浪汉。

不一样。当作为“sh”调用时,它将表现得像 sh 而不是 bash,因此是 bash 特定的 rc/profile 文件(例如 ~/.bash_profile, ~/.bashrc) 不会被获取。但是 ~/.profile 将被读取。您的 问题可能是您正在使用 bash 语法在您的 ~/.profile.

这不起作用:

export PATH=/some/path:$PATH

但这会:

PATH=/some/path:$PATH
export PATH

【讨论】:

  • 在我的情况下 .profile 完全被忽略了。在调用 /bin/sh 时手动获取它实际上会导致正确的路径,但它自己的流浪汉似乎无法获取 ~/.profile。
  • 我不确定是否将export PATH 放在~/.profile~/.bash_profile 中的单独一行会让tramp 理解它,但我试图让EDITOR 由tramp 在类似的方式,它在~/.profile~/.bash_profile 都不起作用,所以我最终通过tramp-remote-process-environment 再次设置它,正如我在emacs.stackexchange.com/a/7685/5165 中所说的那样,这并不完全方便,因为不同的远程主机可能需要不同的值。
【解决方案2】:

我遇到了这个问题,从我的 shell 历史记录中可以看出,tramp 正在将 /bin/sh 作为非登录 shell 执行,这意味着 ~/.profile 不会被执行。

这听起来像 emacs 手册所说的 here:

另一种查找远程路径的方法是使用远程主机分配给远程用户的路径。 Tramp 在登录后通常不会保留此远程路径。但是 tramp-own-remote-path 保留了路径值,可用于更新 tramp-remote-path。

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

请注意,这仅在您的远程 /bin/sh shell 支持登录参数“-l”时才有效。

'tramp-own-remote-path 添加到tramp-remote-path 如上所述,将-l 标志添加到我在历史记录中看到的命令中,并按预期获取~/.profile

(这在the accepted answer 中对Ivan's comment 中链接的问题进行了描述,但没有提到通过采购~/.profile 尊重PATH,这意味着可以在该文件中完成其他环境自定义。)

【讨论】:

    猜你喜欢
    • 2012-05-29
    • 2010-10-17
    • 2012-05-09
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-10-08
    • 2012-04-11
    相关资源
    最近更新 更多