開心生活站

位置:首頁 > IT科技 > 

shell腳本執行linux命令

IT科技1.34W

方式一:

切換到shell腳本所在的目錄(也叫工作目錄)執行shell腳本,具體代碼是:

cd /data/shell

./hello.sh

方式二:

可以以絕對路徑的方法去執行bash shell腳本,具體代碼是:

/data/shell/hello.sh

方式三:

可以選擇直接使用bash命令或者sh命令來執行bash shell腳本,具體代碼是:

cd /data/shell

bash hello.sh

或者

cd /data/shell

sh hello.sh

方式四:

還可以選擇在當前的shell環境中執行bash shell腳本,具體代碼是:

cd /data/shell

. hello.sh

cd /data/shell

source hello.sh

說明:前三種方式執行shell腳本時都需要在當前shell(即父shell)開啓的一個子shell環境中執行,完成之後就會關閉回到原來的shell中,但方式四是直接在當前的shell中執行的。

shell腳本執行linux命令