问题描述
运行xxx.sh文件时报错
[root@localhost tmp]# ./xxx.sh
-bash: ./xxx.sh: /bin/bash^M: 坏的解释器: 没有那个文件或目录
错误原因
这个文件在Windows下编辑过,在Windows下每一行结尾是\n\r,而Linux下则是\n,所以才会有多出来的\r。
处理方法
使用指令sed -i 's/\r$//' xxx.sh,会把 xxx.sh 中的\r 替换成空白。
运行xxx.sh文件时报错
[root@localhost tmp]# ./xxx.sh
-bash: ./xxx.sh: /bin/bash^M: 坏的解释器: 没有那个文件或目录
这个文件在Windows下编辑过,在Windows下每一行结尾是\n\r,而Linux下则是\n,所以才会有多出来的\r。
使用指令sed -i 's/\r$//' xxx.sh,会把 xxx.sh 中的\r 替换成空白。