1. 用絕對路徑或相對路徑執行
/xxx/xx/test.sh 或 ./test.sh, 要求sh文件必須有可執行權限,可以用命令 chmod a+x test.sh來添加
2. 用bash或sh來執行
bash test.sh 或 sh test.sh
3. 用source 或 . 來執行
source test.sh 或 . test.sh 這樣的一大特點是,在本shell執行,前面的方式都是在本shell的子shell中執行,不能獲取sh文件中的變量
參考:https://www.cnblogs.com/zhj868/p/13123752.html