linux环境中替换window换行符为linux换行符

一,错误报文:

bash: $'\r': command not found
bash: $'\r': command not found
bash: $'\r': command not found
/etc/bash.bashrc: line 1: $'return\r': command not found
/etc/bash.bashrc: line 2: $'\r': command not found
/etc/bash.bashrc: line 7: $'\r': command not found
/etc/bash.bashrc: line 18: $'\r': command not found
/etc/bash.bashrc: line 37: $'\r': command not found
bash: $'\E[0': command not found
bash: $'31m\r': command not found
bash: _____: command not found
bash: eval: line 26: syntax error near unexpected token `_'

二,错误原因:

出现的原因是该脚本在window上编辑过,widnow 上文件换行是 \r\n 而 linux上是 \n。
在Windows下换行的“\r”到了Linux环境下不能够识别了,因为Linux环境下默认的换行符为“\n”。

三,解决错误:

此问题解决方式有如下两种:

1,进到脚本中执行

将换行符设置成UNIX的模式

脚本放到linux上 使用 vim 打开,并执行 :set ff=unix 命令 (执行后记得使用 :wq 保存一下)

#=> vim docker-test.sh
#=> :set ff=unix			
#=> :wq
2,借助于dos2unix插件转化功
1)进入Linux环境下安装该组件
apt-get install dos2unix
2)在需实行的目录中执行插件命令
dos2unix *
3)目录中批量替换.py文件中的换行符
sudo find /home/test -name "*.py" | xargs dos2unix
sudo find /home/test -name/* | xargs dos2unix
  • 4
    点赞
  • 9
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
LinuxWindows之间,换行符是不同的。在Windows上,换行符是"\r\n",而在Linux上,换行符是"\n"。因此,当你在Windows上编辑的脚本在Linux上运行时,可能会出现换行符错误的问题。这种错误可以通过转换换行符来解决。在Linux上,你可以使用命令"dos2unix"来将Windows格式的文本文件转换为Linux格式。这个命令会将"\r\n"转换为"\n",以适应Linux换行符要求。这样,你的脚本就可以在Linux上正确运行了。\[1\]\[2\]\[3\] #### 引用[.reference_title] - *1* [linuxwindows换行符](https://blog.csdn.net/qq_35468610/article/details/117981319)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v91^insertT0,239^v3^insert_chatgpt"}} ] [.reference_item] - *2* [linux环境替换window换行符linux换行符](https://blog.csdn.net/TFATS/article/details/120078166)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v91^insertT0,239^v3^insert_chatgpt"}} ] [.reference_item] - *3* [Linux上怎么进行换行符转换](https://blog.csdn.net/weixin_42525264/article/details/116980486)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v91^insertT0,239^v3^insert_chatgpt"}} ] [.reference_item] [ .reference_list ]
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值