[英]How to actually change/set environment variables from within emacs
In my shell I did: export BLA=foo
and then I do echo $BLA
and I see foo
as expected. 在我的shell中我做了: export BLA=foo
,然后我echo $BLA
,我看到foo
如预期的那样。 I then load up emacs and do M-!
然后我加载emacs并做M-!
for a shell command and do echo $BLA
and it's set to something else, bar
. 对于一个shell命令并执行echo $BLA
并将其设置为其他内容, bar
。 So then I run Mx setenv
and give it BLA
and foo
at the prompts but when i do the echo i still see bar
. 那么我运行Mx setenv
并在提示时给它BLA
和foo
但是当我做回声时我仍然看到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 Mx compile
我正在尝试为我想运行Mx compile
一些环境变量执行此操作
setenv
will modify the environment for the processes emacs launch after you set the value. 设置值后, setenv
将修改emacs启动进程的环境。 Running child processes will not be affected. 运行子进程不会受到影响。
Thus, doing a (setenv "FOO" "bar")
and then Mx shell
(provides you have not a running shell yet) will produce a shell with environment variable "FOO" set to "bar". 因此,做一个(setenv "FOO" "bar")
然后Mx shell
(提供你尚未运行的shell)将生成一个环境变量“FOO”设置为“bar”的shell。
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. 您启动Emacs的shell将其环境副本移交给其子进程(Emacs),这就是值从shell传输到Emacs的方式。 Any change the Emacs then performs with its inherited environment will only affect the Emacs process's environment. Emacs随后对其继承环境执行的任何更改都只会影响Emacs进程的环境。 There is no way the Emacs's environment can influence the environment of the shell. Emacs的环境无法影响shell的环境。
If you need to hand information back to the shell, you have to use different techniques like temp files, named pipes, sockets, … 如果需要将信息传递回shell,则必须使用不同的技术,如临时文件,命名管道,套接字,......
If you just want to check the environment of the Emacs itself, use Mx
getenv
to look at variables, or use M-!
如果您只想检查Emacs本身的环境,请使用Mx
getenv
查看变量,或使用M-!
echo $BLA
. 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. 如果这也显示为其他,那么你可能有一个特殊的BLA
,它在每个命令后自动设置为sth,或者根本不可写,如RANDOM
或类似命令。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.