TRAMP ignores tramp-remote-path

My .emacs has the following:

(require 'tramp) (add-to-list 'tramp-remote-path "/some/path") (add-to-list 'tramp-remote-path 'tramp-default-remote-path) 

so when I open the file using tramp over ssh, I expect my PATH to contain /some/path . Instead, launch M-! echo $PATH M-! echo $PATH returns

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

Even if I set export PATH=/hwdisks/data/modules/pkg/git/1.8.4.1/bin/git:$PATH in .bashrc or .profile , PATH set incorrectly.

In the tramp *debug tramp/ssh remotehost* I see that tramp explicitly sets PATH :

 12:28:34.202135 tramp-send-command (6) # PATH=/bin:/usr/bin:/usr/sbin:/usr/local/bin; export PATH 

If I include echo "in .bashrc" in my .bashrc , it appears in the tramp log, so I know that tramp reads it.

How to force tramp to use the correct PATH ?

Emacs Version: 24.2.1
Version for strollers: 2.2.3-24.1

+8
emacs tramp
source share
2 answers

Embarrassingly, the answer is in the tramp manual:

Another possibility is to reuse the path settings of your remote account at login. Typically, these parameters are overwritten because they may not be useful for strollers. These settings are stored in the placement of tramp-own-remote-path. You can activate it through

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

I'm still not sure why it is ignoring other paths added to tramp-remote-path .

+6
source share

I read this in the tramp manual and tried it. Added

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

Then emacs came out, deleted ~/.emacs.d/tramp and restarted as described here

But M-! echo $PATH M-! echo $PATH still shows the value of tramp-default-remote-path instead of the value set in my .bashrc .

The problem is my understanding of loading profiles. The way tramp calls the remote shell to get the remote PATH:

 /bin/sh -l -c 'echo $PATH' /bin:/sbin:/usr/bin:/usr/sbin:/usr/bin/X11:/usr/X11R6/bin:/usr/local/bin:/usr/local/sbin 

Since bash is a call as an input shell and like /bin/sh , it reads .profile instead of .bash_profile or .bashrc .

I found this in the bash man page:

If bash is called with the name sh, it tries to mimic the behavior of running historical versions of sh as close as possible, while according to POSIX. When called as an interactive login shell or a non-interactive shell with the --login option, it first tries to read and execute commands from / etc / profile and ~ / .profile in this order. The -noprofile option can be used to suppress this behavior. When invoked as an interactive shell with the name sh, bash looks for the ENV variable, expands its value, if defined, and uses the expanded value as the read and execute file name. Since the shell called as sh does not try to read and execute commands from any other startup files, the -rcfile option has no effect. The non-interactive shell called by the name sh does not try to read any other startup files. When sh is invoked, bash enters posix mode after reading the startup files.

I usually only configure ~/.bashrc and ~/.bash_profile . For tramp to work correctly, I have to move my .bash_profile to .profile

Hope this helps others.

  • GNU Emacs: 25.0.94.2 Tramp: 2.2.13.25.1
+3
source share

All Articles