What is the difference between “source script.sh”

2020-01-28 03:51发布

What is the difference between source <script> and ./<script>?

标签: linux shell unix
2条回答
Emotional °昔
2楼-- · 2020-01-28 04:11

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.

查看更多
叛逆
3楼-- · 2020-01-28 04:31

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

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

查看更多
登录 后发表回答