运行shell脚本报错:-bash: ./test1.sh: /bin/bash^M: ...
Linux 运行./test1.sh时报错,如下
[root@192 public]# ./test1.sh
-bash: ./test1.sh: /bin/bash^M: bad interpreter: No such file or directory
解决方法
1、在shell文件目录下直接运行
[root@192 public]# sed -i 's/\r$//' test1.sh
2、vim进入test1.sh后,在底部执行set fileformat=unix,后再执行wq保存文件
[root@192 public]# vi test1.sh
再次运行./test1.sh成功
本作品采用《CC 协议》,转载必须注明作者和本文链接