linux报错/bin/bash^M: bad interpreter: No such file or directory问题

执行shell脚本时提示 /bin/bash^M: bad interpreter: No such file or directory

 查看脚本文件是dos格式还是unix格式的几种办法。

(1)cat -A filename  从显示结果可以判断,dos格式的文件行尾为^M$,unix格式的文件行尾为$。
(2)od -t x1 filename 如果看到输出内容中存在0d 0a的字符,那么文件是dos格式,如果只有0a,则是unix格式。
(3)vi filename打开文件,执行 : set ff,如果文件为dos格式在显示为fileformat=dos,如果是unxi则显示为fileformat=unix。

这个错误主要是由于shell脚本文件是dos格式的,在windows系统下编写的代码每一行是以rn来换行,而unix格式的文件行尾则以n来标识。

解决的方法很简单就是把windows格式的文件转换为linux/unix的格式(简单讲就是把(rn)改成n格式)

解决方法:

第一种方式:

用notepad++打开文件,点“编辑/档案格式转换/转为UNIX格式“,保存并上传,问题搞定。

第二种方式:

使用直接使用 linux 命令 dos2unix filename,直接把文件转换为unix格式,有些系统要用 fromdos filename 命令

第三种方式:

用vi打开,:set fileformat=unix,和dos2unix一个意思

总之不管是那种方式,只要目的都是一样的把windows的文件转换为linux/UNIX 文件。

文件编码方式转变一下就可以了:

我编译脚本时虽然也是在linux上,但是我通过邮箱发送过来的,可能经过邮箱发送时被转化为windows格式了吧!

第四种方式:

 [root@localhost bin]# dos2unix myshell.sh
dos2unix: converting file myshell.sh to UNIX format ...

第五种方式

vim mysell.sh

:get fileformat               --->可以看到本文件的格式

:set fileformat=unix     --->就可以将doc转化为unix格式了

时间: 2024-09-03 10:30:01

linux报错/bin/bash^M: bad interpreter: No such file or directory问题的相关文章

linux报错/bin/sh M: bad interpreter: No such file or directory问题

原本今年老蒋就有打算学习Linux脚本方面的内容,于是在之前的各种图书活动中买了不少的书,但是大部分都连塑料封面都还没有拆.今天正好公司没有事情,于是就尝试折腾备份脚本,虽然是有参考网上的一些文档,但是好歹也需要自己摸索一方且修改成较为方便适合我们常规用途的脚本.   我们很多的网友玩Linux脚本修改和撰写的时候都基于Windows系统,所以我们在编辑的脚本文件执行的时候容易出现"/bin/sh^M: bad interpreter: No such file or directory&quo

执行sh脚本:/bin/sh M: bad interpreter: No such file or directory

执行sh脚本错误:/bin/sh^M: bad interpreter: No such file or directory,这是windows下编码不同造成的,在Linux下修复方法如下,记录一下. [nobody@twin14441 cronjob]$ ./stop_tips_new.sh -bash: ./stop_tips_new.sh: /bin/sh^M: bad interpreter: No such file or directory 解决办法:vi该文件 在命令模式下输入 :

/usr/local/php/bin/php^M: bad interpreter: No such file or directory

在使用php作为linux上shell脚本运行时出现了以下错误: /usr/local/php/bin/php^M: bad interpreter: No such file or directory 原因是你的文本以DOS文件形式保存,如下图所示 解决办法,使用dos2unix命令转换文档类型: dos2unix test.php centos安装dos2unix命令: yum -y install dos2unix 以上是小编为您精心准备的的内容,在的博客.问答.公众号.人物.课程等栏目也

Linux 格式化分区 报错Could not stat /dev/sda3 --- No such file or directory

执行分区过程如下: [root@jyrac2 ~]# fdisk /dev/sda The number of cylinders for this disk is set to 3002. There is nothing wrong with that, but this is larger than 1024, and could in certain setups cause problems with: 1) software that runs at boot time (e.g.,

/bin/bash^M: bad interpreter: No such file or dire

    在执行shell脚本时提示这样的错误主要是由于shell脚本文件是dos格式,即每一行结尾以\r\n来标识,而unix格式的文件行尾则以\n来标识.  查看脚本文件是dos格式还是unix格式的几种办法.(1)cat -A filename  从显示结果可以判断,dos格式的文件行尾为^M$,unix格式的文件行尾为$.(2)od -t x1 filename 如果看到输出内容中存在0d 0a的字符,那么文件是dos格式,如果只有0a,则是unix格式.(3)vi filename打开文

bash: /usr/bin/autocrorder: /usr/bin/python^M: bad interpreter: No such file or directory_linux shell

在windows系统下写的python脚本,在linux下赋予权限chmod +x xxx.py 以后,执行./xxx.py运行提示:bash: /usr/bin/autocrorder: /usr/bin/python^M: bad interpreter: No such file or directory 分析: 这是不同系统编码格式引起的:在windows系统中编辑的.sh .py文件可能有不可见字符,所以在Linux系统下执行会报以上异常信息.一般是因为windows行结尾和linux

linux下jsp报错问题-jsp页面在linux报错问题

问题描述 jsp页面在linux报错问题 HTTP Status 500 - javax.servlet.ServletException: File ""/jsp/base/header.jsp"" not found type Exception report message javax.servlet.ServletException: File ""/jsp/base/header.jsp"" not found de

bad interpreter: No such file or directory

在Linux下转换: 在使用php作为linux上shell脚本运行时出现了以下错误: /usr/local/php/bin/php^M: bad interpreter: No such file or directory 原因是你的文本以DOS文件形式保存,如下图所示 解决办法,使用dos2unix命令转换文档类型: dos2unix test.php centos安装dos2unix命令: yum -y install dos2unix 在windows下转换: 利用一些编辑器如Ultra

linux报错/lib/ld-linux.so.2: bad ELF interpreter: No such file or directory

修复: [root@loaclhost scripts]# /usr/local/bin/shc -v -f tmp.sh bash: /usr/local/bin/shc: /lib/ld-linux.so.2: bad ELF interpreter: No such file or directory [rootlocalhost scripts]# yum install glibc [root@localhost scripts]# yum install glibc.i686  [r