2013-01-20 58 views
-1

可能重複:
what is the difference between 「./somescript.sh」 and 「. ./somescript.sh」分離之間的區別。 script.sh VS ./script.sh

請澄清shell命令之間的差異。 script.sh vs ./script.sh其中script.sh是一個shell腳本。

感謝

+0

也http://stackoverflow.com/questions/1880735/difference-between-launching-a-script-可用with-script-sh-and-script-sh?rq = 1 – NPE

+0

而http://stackoverflow.com/questions/9017763/difference-between-and?rq=1 – NPE

回答

4

不同的是簡單

. script.sh 

使用當前的外殼,讓您在腳本中做的所有更改(如更改目錄或變量)會影響您的運行shell執行shell腳本

./script.sh 

另一方面將啓動一個新的shell來執行腳本。它通常是啓動腳本

0

要添加到上面的Fabian給出的答案是更好的方式,

您可以通過以前見過的

echo $$ 

輸出和執行在script.sh後測試既MODES.You會看到從他們process id

而且差別,當你在執行使用. script.sh 所有先前定義的變量externshell仍可

而與./script.sh 那些extern變量將不會爲新shell

相關問題