bash: ./a.sh: /bin/bash^M: bad interpreter: No such file or directory的解决方法------dos--->unix
一些人喜欢用vim来写linux shell script, 但是, 有的人喜欢在Windows下用一些方便的编辑器(比如鼎鼎大名的Notepad++)写好, 然后拷贝文件到linux下, 结果呢, 在执行脚本a.sh的时候, 会出现如下问题:
mracale@ubuntu:~$ ./long.sh
-bash: ./long.sh: /bin/bash^M: bad interpreter: No such file or directory
什么原因呢, 我们有理由怀疑是文件格式问题? 我们用vim a.sh进入a.sh这个文件, 然后在底部模式下, 执行:set ff查看一下, 结果发现fileformat=dos, 看看, 果然是文件格式问题, 那怎么解决呢?
方法一:vim a.sh进入a.sh后, 在底部模式下, 执行:set fileformat=unix后执行:x或者:wq保存修改。 然后就可以执行./a.sh运行脚本了。(我亲自试过, 是ok的)
方法二:直接执行sed -i "s/\r//" a.sh来转化, 然后就可以执行./a.sh运行脚本了。(我亲自试过, 是ok的)
方法三:直接执行dos2unix a.sh来转化, 然后就可以执行./a.sh运行脚本了。(我的linux上执行dos2unix ./a.sh失败, 但是不要放弃啊, 加个busybox就可以了), 如下:
dos2unix a.sh
bash: dos2unix: command not found
[taoge@localhost learn_shell]$ busybox dos2unix a.sh
实际上, 经过上述三种方法修改后, 我们都可以再用:set ff再查一下, 发现a.sh的fileformat果然是unix了。 第一种方法最方便, 建议用第三种!
bash: ./a.sh: /bin/bash^M: bad interpreter: No such file or directory的解决方法------dos--->unix的更多相关文章
- -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 ...
- 【问题解决】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) 进行运行的时候,什么事情没有.但是当把脚本移植到远程服务器进行运行的时候,发现 ...
- 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 ...
- 执行shell脚本时提示bad interpreter:No such file or directory的解决办法
执行shell脚本时提示bad interpreter:No such file or directory的解决办法 故障现象:在终端直接cd /var正常,在shell脚本中执行则报错.原因是脚本是 ...
- 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 ...
随机推荐
- c配置库ccl使用小结
配置文件为key=value键值对形式 下载与安装 库文件下载:ccl-0.1.1.tar.gz 安装: tar -zxvf ccl-0.1.1.tar.gz cd ccl-0.1.1 ./con ...
- 关于spring中注解和xml混合使用
可以混合用.文档有说明: Spring can accommodate both styles and even mix them together. 混合用的话,有个先后顺序,xml配置会覆盖ann ...
- Windows 安装、重装MySQL时,报错:could not start the service mysql
原因: 卸载mysql时并没有完全删除相关文件和服务,需要手动清除. 解决方法: 首先,在管理工具->服务里面将MySQL的服务给停止(有的是没有安装成功,有这个服务,但是已经停止了的). 然后 ...
- GitHub Permission to <<repository>> denied to <<username>>
I kept receiving a 403 error saying my usual username couldn’t access the repository with my usual a ...
- vue-cli打包构建时常见的报错解决方案
报错1:vue-cli项目本地npm run dev启动后,chrome打开是空白页 解决方案:将config下的index.js中的assetsPublicPath路径都设置为‘/’绝对路径 报错2 ...
- 通用性能测试过程模型GAME(A)
1.3.1 Goal(定义目标) 制定一个明确而详细的测试目标是性能测试开始的第一步,也是性能测试成功的关键. 本步骤的开始时间:需求获取阶段 本步骤的输入:性能需求意向 本步骤的输出:明确的性能测 ...
- jquery后加Dom绑定事件
$('#musicCategoryListContainer').on('click', '.musicCategoryItem', function () { $(this).siblings(). ...
- ArcGIS -- ArcSDE Lock request conflicts with an established lock
1.查询下列表是否有数据 select * from sde.state_locks; select * from sde.object_locks; select * from sde.layer_ ...
- UIImage 裁剪图片和等比列缩放图片
本文转载至 http://blog.csdn.net/cuiweijie3/article/details/9514293 转自 http://www.tedz.me/ios/uiimage-crop ...
- vim 命令重新安装
author : headsen chendate: 2018-05-11 09:50:23 [root@localhost ~]# which vim /usr/bin/vim [root@loca ...