设置环境变量并使其在所有打开的终端中均有效 [英] Set a environment variable and make it effective in all opened terminal

查看:154
本文介绍了设置环境变量并使其在所有打开的终端中均有效的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有很多打开的终端.现在,我要设置一个环境变量,并希望该环境变量在所有打开的终端中都有效(不需要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

  1. 创建一个文件~/.env,其中将包含设置.
  2. ~/.bashrc中的
  3. ,告诉每个终端在每个提示符下来源文件:

  1. create a file ~/.env which will contain the settings.
  2. 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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆