具體報錯如下:
./test.sh: line 36: syntax error: unexpected end of file
執行命令時需將test.sh替換為實際的腳本文件名稱。
情形一:
shell腳本在Windows下編寫,上傳到Linux上執行,由于 fileformat 類型不同,所以報錯。
解決方法:
使用vim打開腳本文件,輸入以下命令將fileformat 類型改為unix,回車,然后保存退出。
:set ff=unix
情形二:
shell腳本在Linux下編寫,此時一般不會是fileformat 類型錯誤導致該錯誤,大概率是腳本內容存在錯誤,可以逐步檢查修改,然后使用 sh -n test.sh
命令驗證。