在Shell脚本完成后保留环境变量 [英] Preserve environments vars after shell script finishes
本文介绍了在Shell脚本完成后保留环境变量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
在脚本运行完毕后,如何保留从Shell脚本设置的环境变量?
How can I keep the environment variables, set from a shell script, after the script finishes running?
推荐答案
通过运行脚本无法实现.该脚本会产生它自己的子外壳,脚本完成后会丢失.
This is not possible by running the script. The script spawns it's own sub-shell which is lost when the script completes.
为了保留脚本中可能包含的 export
,请对其进行调用
In order to preserve export
s that you may have in your script, call it
- 要么
. myScript.sh
source myScript.sh
注意.
和 myScript.sh
之间的空间;还请注意," source
是的同义词.
在Bash中,但在POSIX sh
中不是,因此为了获得最大的兼容性,请使用句点"
Notice the space between the .
and myScript.sh
; also note that "source
is a synonym for .
in Bash, but not in POSIX sh
, so for maximum compatibility use the period."
这篇关于在Shell脚本完成后保留环境变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文