sh脚本异常:/bin/sh^M:bad interpreter: No such file or directory

简介:
  在Linux中执行.sh脚本,异常/bin/sh^M: bad interpreter: No such file or directory。 
分析:这是不同系统编码格式引起的:在windows系统中编辑的.sh文件可能有不可见字符,所以在Linux系统下执行会报以上异常信息。 
解决:1)在windows下转换: 
利用一些编辑器如UltraEdit或EditPlus等工具先将脚本编码转换,再放到Linux中执行。转换方式如下(UltraEdit):File-->Conversions-->DOS->UNIX即可。 
2)也可在Linux中转换: 
首先要确保文件有可执行权限 
#sh>chmod a+x filename 
然后修改文件格式 
#sh>vi filename 
利用如下命令查看文件格式 
:set ff 或 :set fileformat 
可以看到如下信息 
fileformat=dos 或 fileformat=unix 
利用如下命令修改文件格式 
:set ff=unix 或 :set fileformat=unix 
:wq (存盘退出) 
最后再执行文件 

#sh>./filename



本文转自 古老 51CTO博客,原文链接:http://blog.51cto.com/yzmlinux/1162318,如需转载请自行联系原作者

相关文章
|
5月前
|
Unix Shell iOS开发
Shell错误:/bin/bash^M: bad interpreter: No such file or directory
Shell错误:/bin/bash^M: bad interpreter: No such file or directory
70 0
|
11月前
|
Java Linux
linux配置jdk环境出现错误:/usr/libexec/grepconf.sh: line 5: grep: command not found 的解决办法
linux配置jdk环境出现错误:/usr/libexec/grepconf.sh: line 5: grep: command not found 的解决办法
270 0
|
12月前
|
Kubernetes Shell 容器
starting container process caused “exec: \“/bin/bash\“: stat /bin/bash: no such file or directory
starting container process caused “exec: \“/bin/bash\“: stat /bin/bash: no such file or directory
221 0
|
移动开发 Unix Shell
/bin/bash^M: bad interpreter: No such file or directory
/bin/bash^M: bad interpreter: No such file or directory
107 0
./autogen.sh: 3: gtkdocize: not found
./autogen.sh: 3: gtkdocize: not found
95 0
|
Shell Linux Windows
-bash usrlocalbindfs binbash^M bad interpreter 没有那个文件或目录
-bash usrlocalbindfs binbash^M bad interpreter 没有那个文件或目录
98 0
|
Shell 数据库管理
/bin/sh: 1: tclsh: not found
/bin/sh: 1: tclsh: not found
273 0
|
移动开发 Unix Shell
shell脚本 解决“/bin/bash^M: bad interpreter: No such file or directory”
shell脚本 解决“/bin/bash^M: bad interpreter: No such file or directory”
123 0
|
Unix Linux Shell
shell解决/bin/bash^M:bad interpreter:No such file or directory
在执行shell脚本时提示这样的错误主要是由于shell脚本文件是dos格式,即每一行结尾以\r\n来标识,而unix格式的文件行尾则以\n来标识。 查看脚本文件是dos格式还是unix格式的几种办法。
2485 0
下一篇
无影云桌面