转: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. UVA 11584 一 Partitioning by Palindromes

    Partitioning by Palindromes Time Limit:1000MS     Memory Limit:0KB     64bit IO Format:%lld & %l ...

  2. Create,Insert

    创建表 create table people ( id int ,name ) ) create table toys ( id int ,name ) ,people_id int ) CREAT ...

  3. 09.VMWare虚拟机copy后网卡不是eth0解决办法

    0.如果VM虚拟机已经复制了,网卡已经不是eth0了,看下面1--->步骤,如果还没复制将要复制,只看1就行     点击I copy it.这时虚拟机会在开机时检查是否次网卡无力地址已经存在, ...

  4. 解决properties文件乱码问题(eclipse和MyEclipse)

    windows——>Preferences——>General——>ContentTypes——>Text——>Java Properties File,设置Defaul ...

  5. Mac : 强大的截图

    来源:http://irising.me/2011/11/12135/ Mac的截图功能扩展功能很强大的,不要用QQ那个COM+Ctrl+A弱爆了的截图了~ 首先说一下两种截图1.Command+sh ...

  6. maven2 配置M2_REPO

    从eclipse中增加了maven2的插件之后,maven默认的本地库的路径是${user}/.m2/repository/下,一般windows用户的操作系统都安装在C盘,所以这个目录 下的jar包 ...

  7. js 读写cookie。不同路径会储存各自的cookie。而 在v.net环境下读写是在 / 根目录。

    所以如果全站不分path 的 话.应该显示的写上 path .设置为根目录 function setCookie(name, value) { document.cookie = name + &qu ...

  8. 36个炫丽的html5 canvas展示

    36个炫丽的html5 canvas展示http://html6game.com/2013/08/03/36-behind-the-html5-canvas-show.shtml 16个最好的CSS3 ...

  9. js学习笔记-编写高效、规范的js代码-Tom

    编写高效.规范的js代码: 1.变量命名空间问题,尽量使用局部变量,防止命名冲突(污染作用域中的全局变量):全局空间命名的变量可以在对应的文档域任意位置中使用window调用. 2.尽量使用单var定 ...

  10. Android listview和ListAdapter搭配使用

    ListView时Android中自带的数据显示控件,要使用ListView填充数据,必须要通过适配器来填充,这里给大家介绍一下ListAdapter适配器,效果图如下: java源码: packag ...