How to set an environment variable in emacs shell (eshell)?
Asked Answered
V

2

18

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?

Vapory answered 5/2, 2013 at 21:9 Comment(3)
You are looking for setenvRushy
What about eshell "cd"-ed into a remote directory via tramp?Schiff
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! ;)Schiff
R
23
~ $ (setenv "XYZ" "abc")
abc
~ $ ./e.sh
abc
~ $ cat e.sh
echo $XYZ
~ $ (setenv "XYZ" "abc")
abc
~ $ ./e.sh
abc
Rushy answered 5/2, 2013 at 21:17 Comment(2)
Why not just setenv XYZ abc?Lenis
I don't remember :(. Maybe I was trying to make it more lisp like, for example I can use the function call in init.el, \*scratch\* buffer, or eshell.Rushy
B
3

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))
Bernardabernardi answered 28/7, 2014 at 19:0 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.