且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

在Shell脚本完成后保留环境变量

更新时间:2023-11-21 11:34:40

通过运行脚本无法实现.该脚本会产生它自己的子外壳,脚本完成后会丢失.

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 exports 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."