可能重複:
what is the difference between 「./somescript.sh」 and 「. ./somescript.sh」分離之間的區別。 script.sh VS ./script.sh
請澄清shell命令之間的差異。 script.sh vs ./script.sh其中script.sh是一個shell腳本。
感謝
可能重複:
what is the difference between 「./somescript.sh」 and 「. ./somescript.sh」分離之間的區別。 script.sh VS ./script.sh
請澄清shell命令之間的差異。 script.sh vs ./script.sh其中script.sh是一個shell腳本。
感謝
不同的是簡單
. script.sh
使用當前的外殼,讓您在腳本中做的所有更改(如更改目錄或變量)會影響您的運行shell執行shell腳本
./script.sh
另一方面將啓動一個新的shell來執行腳本。它通常是啓動腳本
要添加到上面的Fabian給出的答案是更好的方式,
您可以通過以前見過的
echo $$
輸出和執行在script.sh
後測試既MODES.You會看到從他們process id
而且差別,當你在執行使用. script.sh
所有先前定義的變量extern
shell
仍可
而與./script.sh
那些extern
變量將不會爲新shell
也http://stackoverflow.com/questions/1880735/difference-between-launching-a-script-可用with-script-sh-and-script-sh?rq = 1 – NPE
而http://stackoverflow.com/questions/9017763/difference-between-and?rq=1 – NPE