bash 使用 bash_profile 设置环境变量,但 echo 不返回

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/27843695/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-18 12:09:29  来源:igfitidea点击:

set an environment variable using bash_profile, but echo does not return

bashenvironment-variables

提问by sphaughton

recently on mac, i set an environment variable so that it is present in a new shell. today opening a shell it no longer appears in a new shell even when i set it. i have been using:

最近在 mac 上,我设置了一个环境变量,以便它出现在一个新的 shell 中。今天打开一个外壳,即使我设置了它,它也不再出现在新的外壳中。我一直在使用:

export "AVARIABLE=example" >>~/.bash_profile

which has worked fine until now when i run:

到目前为止,当我运行时一直运行良好:

echo $AVARIABLE

i just get a blank line as if it doesn't exist.

我只是得到一个空行,就好像它不存在一样。

this is happening any time i try to set an environment variable permanently now. i can't see what i'm doing wrong?

每当我尝试永久设置环境变量时,都会发生这种情况。我看不出我做错了什么?

thanks in advance

提前致谢

回答by Amit Verma

You are missing an echoin your command. Try this and and then source the ~/.bash_profile:

echo的命令中缺少一个。试试这个,然后获取~/.bash_profile

echo export "AVARIABLE=example" >> ~/.bash_profile

You also have to source the .profileafter you make changes to it.

您还必须.profile在对其进行更改后获取源。

source ~/.bash_profile