linux 上将 文本格式 dos和unix相互转换

爱被打了一巴掌 2023-03-01 10:45 19阅读 0赞

我们经常将window上编辑的shell脚本上传到liunx上执行,发现会报一些错。

  1. [root@node5 ods-app-ansun-first-init]# sh first-input-ansun-e_mb_member.sh
  2. first-input-ansun-e_mb_member.sh: line 2: $'\r': command not found
  3. first-input-ansun-e_mb_member.sh: line 6: $'\r': command not found
  4. 2020-07-24
  5. first-input-ansun-e_mb_member.sh: line 8: $'\r': command not found
  6. first-input-ansun-e_mb_member.sh: line 10: $'\r': command not found
  7. first-input-ansun-e_mb_member.sh: line 12: $'\r': command not found
  8. : command not foundp
  9. first-input-ansun-e_mb_member.sh: line 14: $'\r': command not found
  10. first-input-ansun-e_mb_member.sh: line 16: $'\r': command not found

这个基本上就是文本字符集的问题了,我们可以vi编辑脚本看到

20200724111651521.png

这里看到脚本的文本编码是dos格式,也可以通过命令查看 :set ff

20200724111953262.png20200724112033804.png

命令:set ff=dos #强制转化为dos格式,如果是要转化成unix格式就是 :set ff=unix

再通过w!保存

20200724112213321.png

这样脚本字符集就转换过来了,再次执行脚本就不会报字符的问题了

发表评论

表情:
评论列表 (有 0 条评论,19人围观)

还没有评论,来说两句吧...

相关阅读