shell脚本中的全局环境变量 [英] Global environment variables in a shell script
本文介绍了shell脚本中的全局环境变量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何在bash脚本中设置全局环境变量?
How to set a global environment variable in a bash script?
如果我像
#!/bin/bash
FOO=bar
...或
#!/bin/bash
export FOO=bar
... vars似乎留在本地上下文中,而我希望在脚本执行完成后继续使用它们
...the vars seem to stay in the local context, whereas I'd like to keep using them after the script has finished executing.
推荐答案
使用运行脚本。
. myscript.sh
这将在当前shell环境中运行脚本。
This will run the script in the current shell environment.
export
管理哪些变量可用于新进程,所以如果你说
export
governs which variables will be available to new processes, so if you say
FOO=1
export BAR=2
./runScript.sh
然后 $ BAR
将在 runScript.sh
的环境中可用,但 $ FOO
不会。
then $BAR
will be available in the environment of runScript.sh
, but $FOO
will not.
这篇关于shell脚本中的全局环境变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文