I have installed exec-path-from-shell as well as included the following in my init.el

(when (memq window-system '(mac ns x))

within my ~/.bash_profile I have defined an environment variable called SOLARIS which stores an IP address. I run the command M-x exec-path-from-shell-copy-env (RET) SOLARIS (RET) to 'import' the environment variable. But when I run C-x C-f /ssh:user@$SOLARIS: it throws out the error:

Error running timerL (error "In 'Find Files' source: 'helm-find-files-get-candidates' 
(user-error \"Not a Tramp file name: \\\"/ssh:user@$SOLARIS:\\\"\")")

When I run the find-file command using the explicit IP address instead of the environment variable, it works fine


There is no expansion of shell variables there, either before or after it looks for the TRAMP filename syntax.

I recommend configuring your ssh config file (~/.ssh/config) to have aliases that you can use. Something like, perhaps:

Host solaris
    Hostname w.x.y.z

Then, when you open the file /ssh:user@solaris:… in Emacs, ssh will use the correct ip address for the short host name 'solaris'. If you also specify the IdentityFile option, then it will automatically use the correct ssh key as well. That will save you time since you won't have to type in a password. You can shorten it even more by specifying the User option as well, so that you don't have to type your username every time.

  • thanks but ideally I am looking for a solution which allows me to carry over the .emacs.d to another machine, which might have different environmental variables – Tian Jul 29 '20 at 4:06

I believe it is a problem in helm, which doesn't expand environment variables. I have tried to reproduce the problem:

  1. Download exec-path-from-shell.el from github (melpa doesn't work ATM)
  2. # emacs -Q -l ~/Downloads/exec-path-from-shell.el
  3. Evaluate (when (memq window-system '(mac ns x)) (exec-path-from-shell-initialize)). This results in (("MANPATH" . "/usr/share/man:") ("PATH" . "/usr/share/Modules/bin:/usr/local/bin:/usr/local/sbin:/usr/bin:/usr/sbin")). No problem, I can use any environment variable for my test.
  4. Evaluate M-x exec-path-from-shell-copy-env (RET) MANPATH (RET).
  5. Open the file C-x C-f /ssh:user@$MANPATH:. Obviously an error, but it tries to open /ssh:user@/usr/share/man:: as expected.

I recommend to check, what helm does.

  • melpa works, I initially had problems connecting, turns out that milkbox is officially depreciated, I switched to http://melpa.org/packages/ and it works, nonetheless thanks for the tip! – Tian Jul 30 '20 at 1:50

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.