转: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. DIV的表单布局

    表单布局其实用表格最好了,可是表格的话,无法定位,这个是一个硬伤. <!DOCTYPE html> <html> <head> <meta charset=& ...

  2. extern "C" __declspec(dllexport) __declspec(dllimport) 和 def

    原文:extern "C" __declspec(dllexport) __declspec(dllimport) 和 def 前面的extern "C"  _ ...

  3. [UVA11464]Even Parity(状压,枚举)

    题目链接:https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem ...

  4. SpringMVC 使用Form标签库制作登录表单

    <%@ page language="java" import="java.util.*" pageEncoding="UTF-8"% ...

  5. 键盘unicode值对照表

    A:65 B:66 C:67 D:68 E:69 F:70 G:71 H:72 I:73 J:74 K:75 L:76 M:77 N:78 O:79 P:80 Q:81 R:82 S:83 T:84 ...

  6. hdu 1869 (Floyd)

    http://acm.hdu.edu.cn/showproblem.php?pid=1869 六度分离 Time Limit: 5000/1000 MS (Java/Others)    Memory ...

  7. Python入门-行和缩进

    学习Python与其他语言最大的区别就是,Python的代码块不使用大括号({})来控制类,函数以及其他逻辑判断.python最具特色的就是用缩进来写模块. 缩进的空白数量是可变的,但是所有代码块语句 ...

  8. StopWatch的使用

    //StopWatch在System.Diagnostics命名控件,要使用它就要先引用这个命名空间. //其使用方法如下: //var stopWatch = new StopWatch(); // ...

  9. 面向对象---prototype

    构造函数里的this,外面的new <script> //用工厂方式构造对象 function createPerson(name, sex) //构造函数 { //假想的系统内部工作流程 ...

  10. java位运算符常见用法

    1. 判断int型变量a是奇数还是偶数 a&1 = 0 偶数 a&1 = 1 奇数 2. 求平均值,比如有两个int类型变量x.y,首先要求x+y的和,再除以2,但是有可能x+y的结果 ...