首先需要确认脚本语法没有问题.
用命令vi -b 打开你的SHELL脚本文件,你会。发现每行脚本最后多了个^M。
然后删除掉,就可以了.
还可以利用shellcheck检查
参考一:syntax error near unexpected token `$‘{\r‘‘问题怎么解决_syntax error near unexpected token `$'{\r-CSDN博客
参考二:
运行shell脚本报错:“syntax error near unexpected token 的解决方法`”-CSDN博客