歡迎來到Linux教程網
Linux教程網
Linux教程網
Linux教程網
Linux教程網 >> Linux基礎 >> 關於Linux >> linux執行腳本的三種方式

linux執行腳本的三種方式

日期:2017/3/1 17:01:54   编辑:關於Linux
linux執行腳本的三種方式 目前據我所知有三種 ./bar.sh 是folk的子進程中執行. . ./bar.sh 是把./bar.sh的內容讀取到當前運行環境開始執行 exec ./bar.sh 是把當前進程替換為./bar.sh的進程. www.2cto.com 假設有腳本foo.sh Python代碼 #!/bin/sh A="hello"; echo "before,A is $A" ./bar.sh echo "after ,A is $A" 腳本bar.sh Python代碼 #!/bin/sh A="world"; 執行foo.sh後輸出如下 www.2cto.com before,A is hello after ,A is hello 因為bar.sh是在子進程中執行的,不會影響父進程的變量. 改成 . ./bar.sh後輸出為 before,A is hello after ,A is world 因為bar.sh的內容被提到了父進程中執行了. 然後改為exec ./bar.sh後輸出為 before,A is hello 因為父進程被替換了,所以執行完了子進程之後,後面的語句就不執行了.
Copyright © Linux教程網 All Rights Reserved