在Linux中执行.sh脚本,异常/bin/sh^M

在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

文章出处:飞诺网(http://dev.firnow.com/course/6_system/linux/Linuxjs/20090729/168243.html)

在Linux中执行.sh脚本,异常/bin/sh^M的更多相关文章

  1. 每天一个linux命令(62):sh命令 /Linux中执行shell脚本的4种方法总结

    bash shell 脚本的方法有多种,现在作个小结.假设我们编写好的shell脚本的文件名为hello.sh,文件位置在/data/shell目录中并已有执行权限. 方法一:切换到shell脚本所在 ...

  2. Linux 中执行Shell 脚本的方式(三种方法)

    Shell 脚本的执行方式通常有如下三种: (1)bash script-name 或者 sh script-name:(2)path/script-name或者./script-name:(3)so ...

  3. Linux中执行shell脚本的4种方法总结

    bash shell 脚本的方法有多种,现在作个小结.假设我们编写好的shell脚本的文件名为hello.sh,文件位置在/data/shell目录中并已有执行权限. 方法一:切换到shell脚本所在 ...

  4. Linux中执行shell脚本的4种方法

    bash shell 脚本的方法有多种,现在作个小结.假设我们编写好的shell脚本的文件名为hello.sh,文件位置在/data/shell目录中并已有执行权限. 方法一:切换到shell脚本所在 ...

  5. Linux中执行shell脚本命令的4种方法总结

    bash shell 脚本的方法有多种,现在作个小结.假设我们编写好的shell脚本的文件名为hello.sh,文件位置在/data/shell目录中并已有执行权限. 方法一:切换到shell脚本所在 ...

  6. Linux中执行 .sh 的方法

    linux下执行.sh文件的方法 .sh文件就是文本文件,如果要执行,需要使用chmod a+x xxx.sh来给可执行权限. 是bash脚本么 可以用touch test.sh #创建test.sh ...

  7. 在Linux中执行.sh脚本,异常

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

  8. 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系统中 ...

  9. 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系统中编辑的. ...

随机推荐

  1. 使用iPhone为Apple Watch制作动画

    (原文:Make Animations for APPLE WATCH Using iPhone 作者:Andy Drizen 译者:xiaoying) 无论要做一个像hamburger button ...

  2. OpenJudge_1936:All in All

    描述 You have devised a new encryption technique which encodes a message by inserting between its char ...

  3. @codeforces - 455E@ Function

    目录 @description@ @solution@ @accepted code@ @details@ @description@ 已知 a 序列,并给定以下关系: \[\begin{cases} ...

  4. 使用jQuery的 autocomplete 实现输入框 自动提示补全

    参考网址: https://www.cnblogs.com/jinzhiming/p/6768402.html 插件下载地址: 链接:https://pan.baidu.com/s/1SpP3hixZ ...

  5. python小数据池 is和 == 再谈编码

    1. 小数据池, id() 小数据池针对的是: int, str, bool 在py文件中几乎所有的字符串都会缓存. id() 查看变量的内存地址 2. is和==的区别 is 比较的是内存地址 == ...

  6. @hdu - 6428@ Problem C. Calculate

    目录 @description@ @solution@ @accepted code@ @details@ @description@ 给定 A, B, C,求: \[\sum_{i=1}^{A}\s ...

  7. APICloud原生APP中ajax需要用api.ajax

    报错截屏: APICloud原生APP中ajax请求需要用api.ajax(api对象的ajax方法来替代),否则会将引起请求失败. APICloud api.ajax

  8. thinkphp 本地配置手机移动端,在pc端访问手机端

  9. Android Listview中Button按钮点击事件冲突解决办法

    今天做项目时,ListView中含有了Button组件,心里一早就知道肯定会有冲突,因为以前就遇到过,并解决过,可惜当时没有记录下来. 今天在做的时候,继续被这个问题郁闷了一把,后来解决后,赶紧来记录 ...

  10. EF CodeFirst 实例Demo

    一直想搞一个EFCodeFirst的Demo,让自己通过实例真正了解CodeFirst,方便以后有需求的时候可以有思路.网上查了很多资料,发现很多博主的文章大量重复,根据推荐步骤走并不一定能够成功,而 ...