-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. 条款24:若所有的函数参数可能都需要发生类型转换才能使用,请采用non-member函数

    假设有一个有理数类Rational,有一个计算有理数乘法的成员函数operator*,示例如下: #include <iostream> class Rational { public: ...

  2. [转]每天一个linux命令目录

    [转]每天一个linux命令目录 http://www.cnblogs.com/peida/archive/2012/12/05/2803591.html 开始详细系统的学习linux常用命令,坚持每 ...

  3. 如何设置电脑的IP

    先找到自己的ip,在设置ip. 图1 图2 图3 图4 图5 图6

  4. 【转载】set_input_delay和set_output_delay的选项-max和-min的讨论

    转自:http://www.cnblogs.com/freshair_cnblog/archive/2012/09/12/2681060.html 一.存在背景分析 文档的说法是,set_input_ ...

  5. UIToolbar swift

    // // ViewController.swift // UILabelTest // // Created by mac on 15/6/23. // Copyright (c) 2015年 fa ...

  6. Capacity Scheduler 队列设置

    先附一个官网地址 Capacity Scheduler是YARN中默认的资源调度器. 相关参数配置: 资源分配相关参数 ``` (1) capacity:队列的资源容量(百分比). 当系统非常繁忙时, ...

  7. 1. ProGit-起步

    (1) 版本控制 本地式 大都是采用数据库记录文件的差异 典型的有rcs,主要保存并管理文件补丁,根据补丁去计算各版本文件内容 缺点:无法协同工作 集中式 通过一个单一的集中服务器去管理所有文件的修订 ...

  8. python 字典列表排序operator.itemgetter()

    举例: import operator x = [{'name':'Homer', 'age':39}, {'name':'Bart', 'age':10}] sorted_x = sorted(x, ...

  9. window8左下角窗口和右上角窗口失效解决方法

    win8系统有时会出现任务栏和桌面点击没反应 小常识: “Windows徽标键” 这个键,左右各一个,称为“Windows徽标键”,键冒上的图案为Windows徽标,由此得名. [知识链接]位于计算机 ...

  10. HDU 1598 find the most comfortable road 并查集+贪心

    题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=1598 find the most comfortable road Time Limit: 1000 ...