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!保存

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

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值