:-bash: xxx: /bin/sh^M: bad interpreter: No such file or directory(转)
2018-01-09 14:33
519 查看
我在windows下用notepad++编写了一个shell 脚本,该脚本在执行时报错,报错信息为:
原因:是在windows下编辑时.sh文件的格式为dos格式,该格式下有些不可见字符。而linux只能执行格式为unix格式的脚本。
解决办法有两个:
方法一:使用vi编辑器来修改文件格式。
1.首先用vi命令打开文件
Shell代码
2.在vi命令模式中使用
3.修改文件format为unix
命令:
执行完后再通过set ff命令查看文件格式,结果如下:
方法二:使用dos2unix命令修改文件格式。
OK啦!
转自:http://chenzhou123520.iteye.com/blog/1832890
[root@localhost test]# ./test.sh -bash: ./test.sh: /bin/sh^M: bad interpreter: No such file or directory
原因:是在windows下编辑时.sh文件的格式为dos格式,该格式下有些不可见字符。而linux只能执行格式为unix格式的脚本。
解决办法有两个:
方法一:使用vi编辑器来修改文件格式。
1.首先用vi命令打开文件
Shell代码
[root@localhost test]# vi test.sh
2.在vi命令模式中使用
:set ff命令,可以看到该文件的格式为dos
fileformat = dos
3.修改文件format为unix
命令:
set ff=unix
执行完后再通过set ff命令查看文件格式,结果如下:
fileformat = unix
方法二:使用dos2unix命令修改文件格式。
[root@localhost test]# dos2unix test.sh dos2unix: converting file test.sh to UNIX format ..
OK啦!
转自:http://chenzhou123520.iteye.com/blog/1832890
相关文章推荐
- shell脚本报错:-bash: xxx: /bin/sh^M: bad interpreter: No such file or directory
- 运行shell脚本,错误:-bash: ./xxx.sh: /bin/bash^M: bad interpreter: No such file or directory
- shell脚本报错:-bash: xxx: /bin/sh^M: bad interpreter: No such file or directory
- -bash: xxx: /bin/sh^M: bad interpreter: No such file or directory
- -bash: ./xxx.sh: /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
- -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 --引用自http://blog.csdn.net/xiaaiwu/article/details/49126777
- 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.sh: /bin/bash^M: bad interpreter: No such file or directory
- shell脚本报错:-bash: xxx: /bin/sh^M: bad interpreter: No such file or directory
- 执行.sh文件 报错:-bash: xxx: /bin/sh^M: bad interpreter: No such file or directory
- bash: ./configure: /bin/sh^M: bad interpreter: No such file or directory
- bash:./configure /bin/sh^M: bad interpreter: No such file or directory
- -bash: ./full_build.sh: /bin/bashM: bad interpreter: No such file or directory
- bash: ./a.sh: /bin/bash^M: bad interpreter: No such file or directory的解决方法
- bash: ./a.sh: /bin/bash^M: bad interpreter: No such file or directory的解决方法------dos--->unix
- -bash: ./full_build.sh: /bin/bash^M: bad interpreter: No such file or directory