Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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?

like image 601
Palace Chan Avatar asked Feb 05 '13 21:02

Palace Chan


People also ask

How do I set an environment variable in Linux shell?

In order to set a permanent environment variable in Bash, you have to use the export command and add it either to your “. bashrc” file (if this variable is only for you) or to the /etc/environment file if you want all users to have this environment variable.

What is Eshell in Emacs?

Eshell is a shell written entirely in Emacs Lisp, and it replicates most of the features and commands from GNU CoreUtils and the Bourne-like shells. So by re-writing common commands like ls and cp in Emacs-Lisp, Eshell will function identically on any environment Emacs itself runs on.

How do I set path in Emacs?

emacs . You can set PATH using (setenv "PATH" (format "%s:%s" "/new/path/element" (getenv "PATH"))) .

What path does Emacs use?

Emacs exec-path Emacs has a variable named exec-path . Its value is a list of dir paths. Emacs uses exec-path to find executable binary programs.


2 Answers

~ $ (setenv "XYZ" "abc")
abc
~ $ ./e.sh
abc
~ $ cat e.sh
echo $XYZ
~ $ (setenv "XYZ" "abc")
abc
~ $ ./e.sh
abc
like image 129
Miserable Variable Avatar answered Oct 02 '22 17:10

Miserable Variable


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))
like image 35
jekennedy Avatar answered Oct 02 '22 16:10

jekennedy