Tramp using ssh does not source .bash_profile / .profile

蹲街弑〆低调 提交于 2020-06-25 10:00:45

问题


I'm using Aquamacs (graphical emacs for OSX using emacs 24 and tramp version 2.2.3) to edit some files on a remote server. Tramp is set up to use ssh and works fine in terms of editing files.

It fails when it comes to compiling because the compiler is not in the path. It seems like tramp does not source any of the profile files like .profile or .bash_profile. /bin/sh is a link to /bin/bash so bash should be the shell used by tramp. A shell started within emacs on the remote server won't source anything, too. A ssh connection from a regular terminal emulator (tried Terminal and X11 on OS X) works as expected (everything sourced correctly).

Any ideas?


回答1:


/bin/sh is a link to /bin/bash so bash should be the shell used by tramp.

Its not the same. When invoked as "sh", it will behave like sh and not bash, hence the bash specific rc/profile files (e.g. ~/.bash_profile, ~/.bashrc) won't be sourced. However ~/.profile will be read. Your problem might be you are using bash syntax to setup stuff in your ~/.profile.

This will not work:

export PATH=/some/path:$PATH

But this will:

PATH=/some/path:$PATH
export PATH



回答2:


I had this problem, and could see from my shell history that tramp was executing /bin/sh as a non-login shell, meaning that ~/.profile wouldn't be executed.

This sounds like what the emacs manual is saying here:

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’.

Adding 'tramp-own-remote-path to tramp-remote-path as described added the -l flag to the command I saw in my history and sourced ~/.profile, as expected.

(This is described in the accepted answer to the question linked in Ivan's comment, but it doesn't mention that the PATH is respected by sourcing ~/.profile, which means other environment customization can be done in that file.)



来源:https://stackoverflow.com/questions/10463152/tramp-using-ssh-does-not-source-bash-profile-profile

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!