执行shell脚本提示syntax error: unexpected end of file

具体报错如下:

./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 命令验证。

你可能感兴趣的:(Linux,linux,shell)