Zum Inhalt

Ubuntu 20.04 編輯與執行 shell script

Ubuntu 20.04 編輯與執行 shell script

基於每次更新內核後,總要執行一些固定指令,這時把這些指令直接寫成 shell script 來執行就很方便,就跟 windows 裡的 batch file 一樣。

建立 shell script

會寫 windows batch file 要建立 shell script 就很簡單易懂,建立新文字檔,並將副檔名改為 .sh,然後將要執行的指令都寫進去後存檔。比如末學建立了一個 autoinstall.sh。

修改權限

不修改權限的話,執行時會出現

bash: ./autoinstall.sh: 拒絕不符權限的操作

修改權限很簡單,滑鼠右鍵點開 shell script -> 屬性 -> 權限,將允許檔案作為程式執行打勾。

或是在 terminal 輸入

chmod -R 777 autoinstall.sh

執行 shell script

在當前 shell script 的資料夾裡滑鼠右鍵,選擇以終端機開啟。執行前要先輸入 ./ 不然會出現找不到指令的錯誤,

以末學的例子就是

./autoinstall.sh

就會自動執行 shell script 裡所有的指令了

Schlagwörter:

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.