In my shell I did: export BLA=foo
and then I do echo $BLA
and I see foo
as expected. I then load up emacs and do M-!
for a shell command and do echo $BLA
and it's set to something else, bar
. So then I run M-x setenv
and give it BLA
and foo
at the prompts but when i do the echo i still see bar
. Why would that be and how can I change it? I am trying to do this for some environment variables under which I want to run M-x compile
setenv
will modify the environment for the processes emacs launch after you set the value. Running child processes will not be affected.
Thus, doing a (setenv "FOO" "bar")
and then M-x shell
(provides you have not a running shell yet) will produce a shell with environment variable "FOO" set to "bar".
Your shell in which you've started the Emacs hands over a copy of its environment to its child process (the Emacs), that's how the value is transmitted from the shell to the Emacs. Any change the Emacs then performs with its inherited environment will only affect the Emacs process's environment. There is no way the Emacs's environment can influence the environment of the shell.
If you need to hand information back to the shell, you have to use different techniques like temp files, named pipes, sockets, …
If you just want to check the environment of the Emacs itself, use M-x
getenv
to look at variables, or use M-!
echo $BLA
. If this also is showing sth else, then you probably have a special BLA
which is automatically set to sth after each command, or which isn't writable at all like RANDOM
or similar.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With