转载地址:http://www.cnblogs.com/pipelone/archive/2009/04/17/1437879.html

在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

[shell编程] sh脚本异常:/bin/sh^M:bad interpreter: No such file or directory的更多相关文章

  1. Linux shell 脚本报错:/bin/bash^M: bad interpreter: No such file or directory

    今天遇到一个很诡异的问题,一直运行很正常的shell脚本失败了,只是昨天增加了一个参数而已. 报错信息: /bin/bash^M: bad interpreter: No such file or d ...

  2. Shell脚本报错:-bash: ./switch.sh: /bin/bash^M: bad interpreter: No such file or directory

    在学习shell中测试case参数命令代码如下 #!/bin/bash #switch测试 case $1 in     start)         echo 'start'     ;;      ...

  3. -bash: ./test.sh: /bin/bash^M: bad interpreter: No such file or directory

    刚刚学习SHELL 写了一个简单的例子发生如下错误 -bash: ./test.sh: /bin/bash^M: bad interpreter: No such file or directory ...

  4. bash: ./a.sh: /bin/bash^M: bad interpreter: No such file or directory的解决方法------dos--->unix

    一些人喜欢用vim来写linux shell script, 但是, 有的人喜欢在Windows下用一些方便的编辑器(比如鼎鼎大名的Notepad++)写好, 然后拷贝文件到linux下, 结果呢, ...

  5. -bash: ./switch.sh: /bin/bash^M: bad interpreter: No such file or directory

    问题: 偶然使用 windows 进行编写脚本.使用 wsl (windows subsystem for linux) 进行运行的时候,什么事情没有.但是当把脚本移植到远程服务器进行运行的时候,发现 ...

  6. shell 报错 /bin/bash^M: bad interpreter: No such file or directory

    shell 执行报错: ./test.sh: /bin/bash^M: bad interpreter: No such file or directory 原因:window和linux 的文件格式 ...

  7. window下编写python脚本在linux下运行出错 usr/bin/python^M: bad interpreter: No such file or directory

    今天在windows下使用notepad++写了个python脚本,传到linux服务器执行后提示:-bash: ./logger.py: usr/bin/python^M: bad interpre ...

  8. shell脚本报错:-bash: xxx: /bin/bash^M: bad interpreter: No such file or directory

    当我们把文件从windows系统中编辑的文件拷贝到linux系统中,如果我们执行文件会保存如下的错: shell脚本报错:-bash: xxx: /bin/bash^M: bad interprete ...

  9. bash: /bin/bash^M: bad interpreter: No such file or directory

    在windows下编写shell脚本在linux下运行会出报错: [hadoop@master data]$ ./load_ods_table.sh -bash: ./load_ods_table.s ...

  10. /bin/bash^M: bad interpreter: No such file or directory

    <今天遇到的问题,  网上有非常多类似的文章,  个人记录下来,  加深记忆,  已经明确的就绕路吧.> 运行一个脚本full_build.sh 时, 一直是提示我: -bash: ./f ...

随机推荐

  1. POJ1286 Necklace of Beads

    Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 8263   Accepted: 3452 Description Beads ...

  2. 流程控制 while循环 运算符

    具体知识戳这里 可变数据类型:在id不变的情况下,数据类型内部的元素(value)可以改变 如:列表,字典 不可变类型:value改变,id也跟的改变 如:数字.字符.布尔类型 运算符 #算数运算符# ...

  3. ZOJ1003 Crashing Balloon

    Crashing Balloon Time Limit: 2 Seconds      Memory Limit: 65536 KB On every June 1st, the Children's ...

  4. You have not concluded your merge. (MERGE_HEAD exists)(转)

    Git本地有修改如何强制更新 本地有修改和提交,如何强制用远程的库更新更新.我尝试过用git pull -f,总是提示 You have not concluded your merge. (MERG ...

  5. ajax 请求 ascx

    尝试了很多方法,ajax 都无法请求 ascx 后台方法 求解!

  6. CSS变形

    css3 变形/变换 相关属性 transform transform-origin transform-style:flat/preserve-3d perspective: 长度单位 perspe ...

  7. hdu 1422(贪心)

    重温世界杯 Time Limit : 2000/1000ms (Java/Other)   Memory Limit : 65536/32768K (Java/Other) Total Submiss ...

  8. ModelMap和ModelAndView区别

    首先介绍ModelMap和ModelAndView的作用 ModelMap ModelMap对象主要用于传递控制方法处理数据到结果页面,也就是说我们把结果页面上需要的数据放到ModelMap对象中即可 ...

  9. php发送http请求的两种常用方法

    第一种:使用CURL,直接上代码,开箱即用: <?php // return file_get_contents("http://thinkphp.com/index/index/cr ...

  10. AC日记——由乃与大母神原型和偶像崇拜 洛谷 P3792

    由乃与大母神原型和偶像崇拜 思路: 逆元+线段树维护和+线段树维护平方和+线段树维护最大最小值: 代码: #include <bits/stdc++.h> using namespace ...