最近在學shell腳本編寫,在windows上編寫完之后,通過xshell上傳到linux系統,賦予執行權限之后,執行腳本出現command not found
原因是:.sh腳本在windows系統下用記事本編輯的,不同系統的編碼格式引起的錯誤。
解決:1:首先確保用戶對該文件有讀和寫以及執行的權限
chmod +x test.sh
2:修改文件格式
vim test.sh
利用如下命令查看文件格式
:set ff
或者用
:set fileformat
當執行:set ff或者:set fileformat會出現fileformat=unix或者是fileformat=dos
3:利用如下命令修改文件格式
:set ff=unix 或者 :set fileformat=unix
4:保存並退出
:wq!
5:在次查看文件格式
5:執行腳本