17
votes

I cannot seem to find this anywhere. A lot of times I run commands with an environment variable set like:

export BLA=foo && ./somebinary

How do i do this in eshell? I think the command is called set but i'm not sure how to use it, what would be the above equivalent in eshell?

2
You are looking for setenvMiserable Variable
What about eshell "cd"-ed into a remote directory via tramp?Lester Cheung
To answer my own question - it depend on the transport methods used in tramp - I have been using "scpx" which uses a simple shell and thus not preserving the environment variables that I have setup. Changing it back to "scp" (or "ssh") worked! ;)Lester Cheung

2 Answers

20
votes
~ $ (setenv "XYZ" "abc")
abc
~ $ ./e.sh
abc
~ $ cat e.sh
echo $XYZ
~ $ (setenv "XYZ" "abc")
abc
~ $ ./e.sh
abc
3
votes

I set variables in my bash profile like so:

export WORK_DIR=/Users/me/Documents/some/dir

Then in .emacs I put this:

(let ((work_dir (shell-command-to-string ". ~/.bash_profile; echo -n $WORK_DIR")))
(setenv "WORK_DIR" work_dir))