设置环境变量并使其在所有打开的终端中均有效 [英] Set a environment variable and make it effective in all opened terminal
问题描述
我有很多打开的终端.现在,我要设置一个环境变量,并希望该环境变量在所有打开的终端中都有效(不需要lgout shell并再次登录或使用任何其他额外的命令,例如source来使其生效)不只是我在其中设置环境变量的终端.
I have many opened terminals. Now I want to set a environment variable and wish the environment variable can effective in all opened terminal(do'nt need lgout the shell and login again or any other extra command such as source to make it effective) not just the terminal in which I set the environment variable.
有什么想法吗?
推荐答案
这取决于您使用的Shell类型.例如,在bash中,您可以
It depends on the type of shell you use. For example, in bash, you can
- 创建一个文件
~/.env
,其中将包含设置.
在 -
,告诉每个终端在每个提示符下来源文件:
~/.bashrc
中的- create a file
~/.env
which will contain the settings. in your
~/.bashrc
, tell each terminal to source the file at each prompt:
PROMPT_COMMAND='. ~/.env'
如果更改.env
文件(例如尝试echo TEST=1 > ~/.env
),则在使用新.bashrc
的任何终端中按Enter键后,echo $TEST
都会产生1
.
If you change the .env
file (e.g. try echo TEST=1 > ~/.env
), then after pressing Enter in any terminal that uses the new .bashrc
, echo $TEST
will produce 1
.
这篇关于设置环境变量并使其在所有打开的终端中均有效的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!