linux执行sh脚本报错:$’\r’: 未找到命令的解决

linux执行sh脚本报错:$’\r’: 未找到命令的完美解决方法

原因:

命令直接从windows 复制过来导致的

解决:我是unbutu系统

安装dos2unixapt-get install dos2unix执行dos2unix命令转换文件格式dos2unix sh文件名

linux执行sh脚本报错:$’\r’: 未找到命令的完美解决方法

然后再执行sh文件就执行成功了

补充: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)的选项进行转换后保存即可。

linux执行sh脚本报错:$’\r’: 未找到命令的完美解决方法

原文地址:https://www.cnblogs.com/JOKERMM/p/17085874.html

相关文章:

  • 2022-12-23
  • 2021-07-27
  • 2021-12-18
  • 2022-01-20
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2022-12-23
  • 2021-11-22
  • 2022-12-23
  • 2021-07-30
  • 2021-08-27
  • 2021-07-28
相关资源
相似解决方案