How to really change / set environment variables from emacs

In my shell, I did: export BLA=foo , and then I do echo $BLA , and I see foo , as expected. Then I load emacs and do M-! for the shell command and do echo $BLA , and it installs something else, bar . So, I run Mx setenv and give it BLA and foo at the prompts, but when I do the echo, I still see the bar . Why would this be and how can I change it? I am trying to do this for some environment variables under which I want to run Mx compile

+4
source share
2 answers

setenv will change the environment for starting emacs processes after . Starting child processes will not be affected.

Thus, executing (setenv "FOO" "bar") , and then Mx shell (while you have not yet launched the shell) produces a shell with the environment variable "FOO" set to "bar".

+6
source

Your shell in which you run Emacs passes a copy of its environment to its child process (Emacs), as the value is passed from the shell to Emacs. Any change that Emacs makes to its legacy environment will only affect the Emacs process environment. The environment of Emacs can in no way affect the environment of the shell.

If you need to transfer information back to the shell, you must use various methods, such as temporary files, named pipes, sockets, ...

If you just want to test the Emacs environment, use Mx getenv to view the variables or use M-! echo $BLA . If this also shows sth else, then you probably have a special BLA that is automatically set to sth after each command or which is not writable at all like RANDOM or similar.

+1
source

Source: https://habr.com/ru/post/1489511/


All Articles