运行shell脚本时出现:syntax error near unexpected token `$’\r“的错误,一般是格式的问题,比如直接从txt文档拷贝过来的内容; 例如test.sh脚本 解决方法:sed -i ‘s/\r//g’ test.sh 然后再执行 sh test.sh