-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
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
-bash: ./test.sh: /bin/bash^M: bad interpreter: No such file or directory的更多相关文章
- 【问题解决】syntax error: unexpected end of file或-bash: ./full_build.sh: /bin/bash^M: bad interpreter: No
在阅读的过程中有不论什么问题,欢迎一起交流 邮箱:1494713801@qq.com QQ:1494713801 运行一个脚本full_build.sh 时, 一直是提示我: -bash: ./ ...
- 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' ;; ...
- -bash: ./switch.sh: /bin/bash^M: bad interpreter: No such file or directory
问题: 偶然使用 windows 进行编写脚本.使用 wsl (windows subsystem for linux) 进行运行的时候,什么事情没有.但是当把脚本移植到远程服务器进行运行的时候,发现 ...
- bash: ./a.sh: /bin/bash^M: bad interpreter: No such file or directory的解决方法------dos--->unix
一些人喜欢用vim来写linux shell script, 但是, 有的人喜欢在Windows下用一些方便的编辑器(比如鼎鼎大名的Notepad++)写好, 然后拷贝文件到linux下, 结果呢, ...
- nagios监控客户端报错/usr/bin/perl^M: bad interpreter: No such file or directory
nagios服务端监控客户端内存时发现监控不上 在客户端直接执行脚本,报错如下: # /usr/local/nagios/libexec/check_memory.pl -w 6% -c 3% -ba ...
- 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 ...
- 执行Python "/bin/usr/python: bad interpreter: No such file or directory" 错误
今天在电脑上写了一个Python脚本,写好之后用ftp传上去,然后执行/var/www/cron.py,结果报错,/bin/usr/python: bad interpreter: No such f ...
- sh脚本异常:bad interpreter: No such file or directory
转:http://bluedest.iteye.com/blog/1674963 在Linux中执行.sh脚本,异常/bin/sh^M: bad interpreter: No such file o ...
- -bash: ./xxx.sh: /bin/bash^M: bad interpreter: No such file or directory
问题的原因是在windows下编辑然后上传到linux系统里执行的..sh文件的格式为dos格式.而linux只能执行格式为unix格式的脚本. 不要使用记事本编辑,使用代码编辑器可以正常执行
随机推荐
- Oracle数据 行转列
记录一段行转列SQL代码: select cs.standard_id,cs.area_code,cs.exu_dept, regexp_substr(exu_dept, , level) as de ...
- 加濾鏡效果GlowTween
/** * * new GlowTween(xxxx, 0xFFFF00); * new GlowTween(xxxx, 0x00FFFF); * GlowTween */ package com.r ...
- springmvc jstl
springmvc运用maven的jetty插件运行成功,部署在tomcat6报错:ClassNotFoundException: javax.servlet.jsp.jstl.core.Config ...
- 超级实用且不花哨的js代码大全
事件源对象 event.srcElement.tagName event.srcElement.type 捕获释放 event.srcElement.setCapture(); event.srcEl ...
- Majority Element,Majority Element II
一:Majority Element Given an array of size n, find the majority element. The majority element is the ...
- Jquery中bind和live.one,delegate的区别
Jquery中绑定事件有三种方法:以click事件为例 (1)target.click(function(){}); (2)target.bind("click",function ...
- Android周笔记(9.8-14)(持续更新)
本笔记记录一周内的小知识点和一些心学习的Demo. 1.PopupWindow: new 一个activity_pop_window:id为popwindow的Button,id为hello123的T ...
- Android 模块化编程之引用本地的aar
转: http://www.stormzhang.com/android/2015/03/01/android-reference-local-aar/ 随着项目越来越多,代码的复用就变得异常重要,这 ...
- accordion
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...
- model、dao、 service 和Comtroll层的关系
首先这是现在最基本的分层方式,结合了SSH架构.modle层就是对应的数据库表的实体类.Dao层是使用了Hibernate连接数据库.操作数据库(增删改查).Service层:引用对应的Dao数据库操 ...