xshell执行脚本提示:$‘\r‘: 未找到命令的解决办法


原因
在执行shell脚本时,出现‘$’\r’: 未找到命令’错误。基本是在Windows系统编写的脚本在linux服务器中执行了。

方法一:
1,使用dos2unix工具将脚本转换为unix版本的。
linux使用yum安装如下:

[root@localhost ~]# yum install dos2unix

ubuntu安装如下:

[root@localhost ~]# sudo apt-get install dos2unix

使用dos2unix对脚本进行转换:

[root@localhost ~]# dos2unix xxx.sh

转换后提示如下:

[root@localhost ~]# dos2unix deLog.sh 
dos2unix: converting file deLog.sh to Unix format ...

再次执行脚本即可。

2,使用nodepad++等工具进行转换。

使用方法:在右下角有转为 Unix (LF)的选项进行转换后保存即可。

 

猜你喜欢

转载自blog.csdn.net/Xin_shou__/article/details/128298069