在执行shell脚本时,会出现‘$’\r’: 未找到命令’错误。

原因分析:

脚本由windows上传至Linux服务器,windows的换行符为"/r/n",而unix的换行符为"/n" 从而导致不识别

解决方案:

1用vim打开shell脚本,执行以下命令

:set ff=unix #转换为unix格式
:wq #保存、退出

  

2安装dos2unix

yum install dos2unix

 

执行dos2unix即可

dos2unix xxx.sh

 

posted @ 2022-05-13 18:26  谢端阳  阅读(196)  评论(0)    收藏  举报