执行脚本时报错:/bin/bash^M: bad interpreter: No such file or directory
来源:互联网 发布:汽车动力学仿真软件 编辑:程序博客网 时间:2024/05/19 20:45
问题症状:今天在windows上编辑了一个linux的shell脚本,然后上传到linux服务器上执行报错,使用ftp的bin模式上传也报错,错误如下:
[root@rh6 inspect]# ./Inspect_LINUX_once.sh
-bash: ./Inspect_LINUX_once.sh: /bin/bash^M: bad interpreter: No such file or directory
原因:就是刚才提到了是由于本人在windows上编辑了脚本,由于windows与linux一些字符编码不一致,所以导致linux在执行的时候有些字符linux不能识别导致报错。
解决方法:知道原因后,解决起来就好办了,这里列出两种解决方法
1.linux提供了一个dos2unix的包,安装此包后,会产生一个dos2unix命令,来转换脚本内容
[root@rh6 inspect]# yum -y install dos2unix*
[root@rh6 inspect]# dos2unix Inspect_LINUX_once.sh
dos2unix: converting file Inspect_LINUX_once.sh to UNIX format ...
[root@rh6 inspect]# ./Inspect_LINUX_once.sh
再次执行不会报错,推荐使用此方法,不过该方法需要安装包,对于不方便安装此包的人来说就不方便了,可以参考下面的方法
2.使用sed命令将特殊字符替换:
[root@rh6 inspect]# sed 's/^M//' Inspect_LINUX_once.sh > tmp.sh
[root@rh6 inspect]# chmod a+x tmp.sh
[root@rh6 inspect]# ./tmp.sh
再执行也不报错,注意:sed里的^M这个是一个字符而不是^和M两个字符,它的输入方法为 按住Ctrl键再按V键按M键,切忌是按住Ctrl键再按V按M键。
- 执行脚本时报错:/bin/bash^M: bad interpreter: No such file or directory
- 执行脚本时报-bash: ./checktom.sh: /bin/sh^M: bad interpreter: No such file or directory错
- Shell脚本执行时报错: /bin/sh^M: bad interpreter: No such file or directory
- centos下执行脚本,报错: /bin/bash^M: bad interpreter: No such file or directory
- shell脚本报错:-bash: xxx: /bin/sh^M: bad interpreter: No such file or directory
- shell脚本报错:-bash: xxx: /bin/sh^M: bad interpreter: No such file or directory
- shell脚本报错:-bash: xxx: /bin/sh^M: bad interpreter: No such file or directory
- shell脚本报错:-bash: xxx: /bin/sh^M: bad interpreter: No such file or directory
- shell脚本报错:-bash: xxx: /bin/sh^M: bad interpreter: No such file or directory
- shell脚本报错:-bash: xxx: /bin/sh^M: bad interpreter: No such file or directory
- shell脚本报错:-bash: xxx: /bin/sh^M: bad interpreter: No such file or directory
- /bin/bash^M: bad interpreter: No such file or directory
- /bin/bash^M: bad interpreter: No such file or directory
- /bin/bash^M: bad interpreter: No such file or directory
- /bin/bash^M: bad interpreter: No such file or directory
- /bin/bash^M: bad interpreter: No such file or directory
- “/bin/bash^M: bad interpreter: No such file or directory
- /bin/bash^M: bad interpreter: No such file or directory
- java正则表达式截取字符串
- 无边框窗体缩放移动代码以及总结
- JAVA数据源连接方式汇总
- Windows安装zookeeper
- 通知栏传值一直为第一次的传值的解决办法
- 执行脚本时报错:/bin/bash^M: bad interpreter: No such file or directory
- Mysql JDBC URL 中常用参数说明
- android平台使用Alljoyn
- Java nio 之 buffer order
- MFC运行程序顺序
- 【Cocoa and Object-c : Up and Running 笔记】02 基本认识
- fms服务端api资料
- 游戏的目标(一)
- DiskFileItemFactory类的使用