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

VI打开文件,没发现任何问题,

把/bin/bash改成/bin/sh

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

依然报错,脚本内容在VI下没有任何问题,仔细一看错误消息,^M..明显在第一行末尾被加入了个^M,

这种情况应该有两种原因

1.在WIN底下用文本编辑工具修改过参数变量,在保存的时候没注意编码格式造成的,

2.也有可能是在VIM里修改,第一行末尾按到ctrl_v

错误原因之一很有可能是你的脚本文件是DOS格式的, 即每一行的行尾以\r\n来标识, 其ASCII码分别是0x0D, 0x0A. 
可以有很多种办法看这个文件是DOS格式的还是UNIX格式的, 还是MAC格式的 
(1). vi filename 
然后用命令 
:set ff? 
可以看到dos或unix的字样. 如果的确是dos格式的, 那么你可以用set ff=unix把它强制为unix格式的, 然后存盘退出. 再运行一遍看.

2.可以用执行dos2unix 命令转换编码

#dos2unix myshell.sh

3..也可以用sed 这样的工具来做: 
sed 's/^M//' filename > tmp_filename 
mv -f tmp_filename filename 
来做 
特别说明:^M并不是按键shift + 6产生的^和字母M, 它是一个字符, 其ASCII是0x0D, 生成它的办法是先按CTRL+V, 然后再回车(或CTRL+M)

关于^M

new line of DOS/Windows

new line of dos/win:   0X0d0a 
new line of linux/unix: 0X0a

执行脚本出现bin/bash: bad interpreter: No such file or directory的更多相关文章

  1. 转载:执行脚本出现bin/bash: bad interpreter: No such file or directory

    转载网址:http://blog.csdn.net/red10057/article/details/8051650 刚刚学习 SHELL 写了一个简单的例子 发生如下错误 -bash: ./test ...

  2. 【转】执行脚本出现bin/bash: bad interpreter: No such file or directory

    [转自]http://blog.csdn.net/wind19/article/details/4822666 错误原因之一很有可能是你的脚本文件是DOS格式的, 即每一行的行尾以/r/n来标识, 其 ...

  3. 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 ...

  4. centos 7安装mysql报错-bash: ./scripts/mysql_install_db: /usr/bin/perl: bad interpreter: No such file or directory

    [root@localhost mysql]# ./scripts/mysql_install_db  --user=mysql -bash: ./scripts/mysql_install_db: ...

  5. -bash: /usr/bin/yum: /usr/bin/python: bad interpreter: No such file or directory

    -bash: /usr/bin/yum: /usr/bin/python: bad interpreter: No such file or directory python多版本造成额问题 找不到p ...

  6. -bash: /usr/local/mysql/scripts/mysql_install_db: /usr/bin/perl: bad interpreter: No such file or directory

    安装 MySQL 初始化时,报错如下: [root@hcdb1 ~]# /usr/local/mysql/scripts/mysql_install_db --defaults-file=/etc/m ...

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

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

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

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

  9. docker容器启动时执行脚本 run /bin/bash执行多条指令

    搜了很多资料发现并未解决,以下方法失败!求大神评论给出完美方案 1.首先需要编写需要启动的脚本,并将脚本放在 /etc/init.d/目录下 如:cs.sh 2.修改权限 3.chkconfig -- ...

随机推荐

  1. MYSQL 一些用法

    LOAD DATA LOCAL INFILE 'C:/xampp/htdocs/test/file/sample.csv' INTO TABLE sample1 FIELDS TERMINATED B ...

  2. Win8.1+vs2012+osg环境搭建

    Win8.1+vs2012+osg环境搭建 一.    相关准备 a) Osg源码 当前最新版:OpenSceneGraph-3.2.0.zip 下载链接: http://www.opensceneg ...

  3. [shell实例]——用脚本实现向多台服务器批量复制文件(nmap、scp)

    练习环境: (1)所有服务器将防火墙和selinux关闭 (2)所有服务器的root密码设置为aixocm (3)所有服务器都为10.0.100.*网段,并保证能够和其它主机通信 (4)所有服务器确保 ...

  4. Linux学习之路--启动VNC服务

    我的Linux是Fedora 13,安装方法如下: 1.打开终端,执行 # yum install -y tigervnc tigervnc-server 2.编辑/etc/sysconfi/vncs ...

  5. 以前用过Extjs技术的开发人员在学习Extjs4时需要注意的问题

            以前学习过Extjs的同学,在学习Extjs4的时候需要注意几个关键改变: 1.Extjs4的新的类系统. 2.Extjs4中MVC思路 3.Extjs4中的新的命名规范(结合新的MV ...

  6. JS 学习笔记--11---内置对象(Global/Math)

    练习中使用的浏览器是IE10,如果各位朋友有不同意见或者遇到浏览器不兼容问题,希望指正 1.内置对象的定义:有ECMAScript实现提供的.不依赖与宿主环境的对象,在ECMAScript运行之前就已 ...

  7. 【BZOJ】【1874】取石子游戏

    SG函数 嗯博弈论入门题,关于SG函数这个东西可以去看VFK神犇的博客,讲的非常清楚Orz. 传送门:vfleaking.blog.163.com/blog/static/17480763420123 ...

  8. SimpleDateFormat

    范例: Date date = new Date();SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MMM-dd,E,HH. ...

  9. 来自平时工作中的javascript知识的积累---持续补充中

    ① SeaJs和RequireJS最大的区别 解惑:来自豆友 ② javascript中如何判断undefined var exp = undefined; if (exp === undefined ...

  10. Oracle 时间处理(加减)

    一. 类似SQL SERVER中DateAdd select sysdate,add_months(sysdate,12) from dual;        --加1年 select sysdate ...