build.sh 出现bash: $'\r': command not found

2025-04-18 04:04:43

1、问题表述:在Windows下编写好sh文件后,在Linux下运行会报错:bash: $’\r’: command not found

build.sh 出现bash: $'\r': command not found

2、出现这种问题是因为wi艘绒庳焰ndows下的文件换行用的是\r\n 而linux系统用的是\n,如果win下的文档上传到linux,每行的结尾都会出现一个^M(^M是ctrl+v,ctrl+m),通过vim -b buil.sh 会发现^M。

build.sh 出现bash: $'\r': command not found

3、解决方案一:通过vim编辑直接删除^M后保存就行,但是如果文档的内容比较长就悲剧了

build.sh 出现bash: $'\r': command not found

4、解决方案二:使用vim打开文件,然后使用命令:set ff=unix,保存文件

build.sh 出现bash: $'\r': command not found
build.sh 出现bash: $'\r': command not found

5、总结:1. 问题陈述2. 发现问题原因3. 提供解决方案

声明:本网站引用、摘录或转载内容仅供网站访问者交流或参考,不代表本站立场,如存在版权或非法内容,请联系站长删除,联系邮箱:site.kefu@qq.com。
猜你喜欢