转:http://bluedest.iteye.com/blog/1674963

在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

sh脚本异常:bad interpreter: No such file or directory的更多相关文章

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

    在Linux中执行.sh脚本,异常/bin/sh^M: bad interpreter: No such file or directory. 分析:这是不同系统编码格式引起的:在windows系统中 ...

  2. sh脚本异常,binsh^M bad interpreter No such file or directory

    错误 在Linux中执行.sh脚本,出现如下异常 /bin/sh^M: bad interpreter: No such file or directory 原因 在windows系统中编辑的.sh文 ...

  3. Linux中运行.sh脚本,异常/bin/sh^M: bad interpreter: No such file or directory。

    在Linux中运行.sh脚本,异常/bin/sh^M: bad interpreter: No such file or directory. 分析:这是不同系统编码格式引起的:在windows系统中 ...

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

    在Linux中执行.sh脚本,异常/bin/sh^M: bad interpreter: No such file or directory.这是不同系统编码格式引起的:在windows系统中编辑的. ...

  5. [shell编程] sh脚本异常:/bin/sh^M:bad interpreter: No such file or directory

    转载地址:http://www.cnblogs.com/pipelone/archive/2009/04/17/1437879.html 在Linux中执行.sh脚本,异常/bin/sh^M: bad ...

  6. python/shell脚本报异常^M: bad interpreter: No such file or directory

    问题:在Windows写了一python脚本,上传Linux服务器执行,报异常*****^M: bad interpreter: No such file or directory 原因:window ...

  7. windows系统编辑过的脚本文件,在linxu上执行报错 /bin/sh^M: bad interpreter: No such file or directory

    如题! 现象: 当时的场景是这样的:我在IDEA中编辑了项目中的脚本sh,然后利用maven打成zip包.把zip包上传到linux服务器解压运行. 当在linux服务器上运行该sh脚本文件时,提示错 ...

  8. Linux学习笔记之Linux shell脚本运行出现问题:bash: ./test: bin/sh: bad interpreter: No such file or directory

    问题: 在Linux系统中使用“vi test.sh”命令创建.sh文件,保存文件(:wq)并赋予权限(chmod +x test.sh)后,执行(./test.sh),出现问题:“bash: ./t ...

  9. bin/sh^M: bad interpreter: No such file or directory解决

    问题:bin/sh^M: bad interpreter: No such file or directory 原因:.sh脚本在windows系统下用记事本文件编写的.不同系统的编码格式引起的. 解 ...

随机推荐

  1. bzoj 3234: [Ahoi2013]立方体

    题目链接:http://www.lydsy.com:808/JudgeOnline/problem.php?id=3234 题意:求长方体交的表面积. 思路:flood-fill const int ...

  2. Cookie 总结

    设置Cookie //设置cookie Cookie cookie = new Cookie("TOM","111"); //设置有效期,默认秒为单位 cook ...

  3. [SAP ABAP开发技术总结]Form(subroutine)、Function参数传值传址

    声明:原创作品,转载时请注明文章来自SAP师太技术博客( 博/客/园www.cnblogs.com):www.cnblogs.com/jiangzhengjun,并以超链接形式标明文章原始出处,否则将 ...

  4. zoj 2107&&hdu 1007最近点对问题

    http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=1107 Quoit Design Time Limit: 5 Seconds   ...

  5. 发布《Linux工具快速教程》

    发布<Linux工具快速教程> 阶段性的完成了这本书开源书籍,发布出来给有需要的朋友,同时也欢迎更多的朋友加入进来,完善这本书: 本书Github地址:https://github.com ...

  6. jsp get方式请求参数中包含中文乱码问题解决

    1. 自己接收到参数之后在后台进行转码处理 2: 修改tomcat的配置文件  server.xml <Connector port="8080" protocol=&quo ...

  7. 如何将自己开发的标签打成jar包

    1: 在Myeclipse中新建一个java工程 2: 将你的标签处理器类统统都拷到工程里面, 将tld文件拷到META-INF里面 3:点击file里面的export,

  8. ASP.NET常用正则表达式

    验证数字:^[0-9]*$ 验证n位的数字:^\d{n}$ 验证至少n位数字:^\d{n,}$ 验证m-n位的数字:^\d{m,n}$ 验证零和非零开头的数字:^(0|[1-9][0-9]*)$ 验证 ...

  9. Spring AOP执行方法

      execution(* springinaction.springidol.Instrument.play(..)) * 代表返回为任意类型 springinaction.springidol.I ...

  10. [转载] zookeeper 事件通知

    ZK事件回调当一个client访问ZK时,client与ZK保持长连接.应用可以通过client的api注册一些callback,当对应的事件发生时,client会执行对应的callback.如果你基 ...