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

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

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

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

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

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

再通过w!保存

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

猜你喜欢

转载自blog.csdn.net/shrek11/article/details/107556898
今日推荐