What is the difference between “source script.sh” and “./script.sh”?

前端 未结 2 414
你的背包
你的背包 2020-12-01 06:16

What is the difference between source

相关标签:
2条回答
  • 2020-12-01 06:40

    source script will change your current environment, ./script will not.

    (EDIT: script has to be executable to use ./)

    0 讨论(0)
  • 2020-12-01 07:01

    source script.sh runs the script within the current process, thus all variable assignments are preserved as variables even after the script finishes (and don't have to be explicitly export'd).

    ./script.sh just runs the script in a subprocess, and any variables which are assigned disappear after the script is done.

    0 讨论(0)
提交回复
热议问题