原因: 我的脚本是在windows上创建并编辑的。 windows下的换行是\r\n 而linux下的换行只是\n 解决办法: 显示换行符 将\r\n替换为\n (这里我使用的是Notapad++的替换,快捷键为Ctrl + H) 或者在创建sh文件的时候使用如下设置(使用Notepad++编辑) 相关文章: linux shell脚本无法执行,报错syntax error near unexpected token `$'\r''解决方法 2021-04-01 运行脚本:syntax error near unexpected token `$'{\r' 2021-07-31 phpcms Parse error: syntax error, unexpected T_ENCAPSED_AND_WHITESPACE错误 2021-07-13 解决VS2013编译错误error C1010: unexpected end of file while looking for precompiled header 2021-11-16 syntax error near unexpected token shell 2021-07-09 soapUI创建连接报错:error loading WSDL或者Unexpected end of file from server 2021-04-19 unexpected end of input 报错处理 2021-12-21 解决shell脚本“syntax error near unexpected token `fi'”的问题。 2021-04-13