美文网首页
centos中运行shell脚本时出现 "line2: $'\r

centos中运行shell脚本时出现 "line2: $'\r

作者: 是彬不是杉 | 来源:发表于2019-05-15 08:47 被阅读0次

原文链接:https://www.whongbin.com/archives/260.html

我的博客中有几篇分享shell脚本的文章,我都是直接把代码粘贴到文章中的,今天我发现脚本直接复制保存到文件中居然无法运行。。。出现如下错误

https://ws1.sinaimg.cn/large/0064eL5bly1g31po6augkj30gz02mgm5.jpg

考虑到代码是在windows下编辑后粘贴在文章中的,可能会出现编码格式不兼容的情况,于是找了下解决方案。如下:

解决方案:

  • ubuntu下:
   sudo apt-get install dos2unix
   dos2unix **.sh
  • centos下:
    yum install dos2unix
    dos2unix **.sh

然后再执行脚本,完美运行

相关文章

网友评论

      本文标题:centos中运行shell脚本时出现 "line2: $'\r

      本文链接:https://www.haomeiwen.com/subject/iyduaqtx.html