Preserve environments vars after shell script finishes

后端 未结 3 1920
别那么骄傲
别那么骄傲 2021-01-11 14:14

How can I keep the environment variables, set from a shell script, after the script finishes running?

3条回答
  •  自闭症患者
    2021-01-11 14:26

    This is not possible by running the script. The script spawns it's own sub-shell which is lost when the script completes.

    In order to preserve exports that you may have in your script, you can call them like this, which will add them to the current environment:

    . myScript.sh

    Notice the space between the . and the myScript.sh section.

提交回复
热议问题