执行shell脚本报syntax error: unexpected end of file错误

  • 原因:
    我的脚本是在windows上创建并编辑的。
    windows下的换行是\r\n
    而linux下的换行只是\n
  • 解决办法:
  1. 显示换行符
    执行shell脚本报syntax error: unexpected end of file错误
  2. 将\r\n替换为\n (这里我使用的是Notapad++的替换,快捷键为Ctrl + H)
    执行shell脚本报syntax error: unexpected end of file错误
  • 或者在创建sh文件的时候使用如下设置(使用Notepad++编辑)
    执行shell脚本报syntax error: unexpected end of file错误
    执行shell脚本报syntax error: unexpected end of file错误