Linux - /bin/sh^M: bad interpreter: No such file or directory
问题
在Windows环境下用Notepad++写了个shell脚本,上传到Linux平台后运行报错如下:
/bin/sh^M: bad interpreter: No such file or directory
经过查阅资料才知道,这是由于文件格式的问题:使用vi/vim进入该shell文件,按下:进入末行模式,输入set ff查询文件格式,结果如下:
fileformat=dos
这个问题是由于不同的操作系统使用了不同的符号来换行导致的,可以简单参考下下面的表格:
| 系统 | 换行符 |
|---|---|
| DOS | CR/LF |
| UNIX | LF |
| MAC | CR |
如果通过Windows下的Git将文件提交到Linux上的服务器,也会收到换行符将被替换的消息通知。
解决方案
通过vi/vim进入想要修改的文件,按下:进入末行模式,输入set fileformat=unix,接着按下ZZ或者按下shift + z + z或者输入:x或者:wq保存修改即可。
参考链接
- bash: ./a.sh: /bin/bash^M: bad interpreter: No such file or directory的解决方法
- DOS、Mac 和 Unix 文件格式+ UltraEdit使用
- [DOS文件转换成UNIX文件格式详解](https://ww
Linux - /bin/sh^M: bad interpreter: No such file or directory的更多相关文章
- Linux中运行.sh脚本,异常/bin/sh^M: bad interpreter: No such file or directory。
在Linux中运行.sh脚本,异常/bin/sh^M: bad interpreter: No such file or directory. 分析:这是不同系统编码格式引起的:在windows系统中 ...
- linux sh脚本异常:/bin/sh^M:bad interpreter: No such file or directory
在Linux中执行.sh脚本,异常/bin/sh^M: bad interpreter: No such file or directory.这是不同系统编码格式引起的:在windows系统中编辑的. ...
- sh脚本异常:/bin/sh^M:bad interpreter: No such file or directory
在Linux中执行.sh脚本,异常/bin/sh^M: bad interpreter: No such file or directory. 分析:这是不同系统编码格式引起的:在windows系统中 ...
- [shell编程] sh脚本异常:/bin/sh^M:bad interpreter: No such file or directory
转载地址:http://www.cnblogs.com/pipelone/archive/2009/04/17/1437879.html 在Linux中执行.sh脚本,异常/bin/sh^M: bad ...
- /bin/sh^M: bad interpreter: No such file or directory 问题解决
我系统为windows,.sh文件的格式为dos,上传到linux上报错/bin/sh^M: bad interpreter: No such file or directory,linux只能执行格 ...
- windows系统编辑过的脚本文件,在linxu上执行报错 /bin/sh^M: bad interpreter: No such file or directory
如题! 现象: 当时的场景是这样的:我在IDEA中编辑了项目中的脚本sh,然后利用maven打成zip包.把zip包上传到linux服务器解压运行. 当在linux服务器上运行该sh脚本文件时,提示错 ...
- shell脚本报错:-bash: xxx: /bin/sh^M: bad interpreter: No such file or directory
今天执行一个shell脚本,然后在执行的时候报错,脚本内容很简单,仅供测试: #!/bin/sh echo "test shell " 具体报错信息如下 [root@localho ...
- bin/sh^M: bad interpreter: No such file or directory解决
问题:bin/sh^M: bad interpreter: No such file or directory 原因:.sh脚本在windows系统下用记事本文件编写的.不同系统的编码格式引起的. 解 ...
- /bin/sh^M:bad interpreter: No such file or directory
bash脚本:/bin/sh^M:bad interpreter: No such file or directory dos2unix 实际上就是把文本文件中面的^M删除 用SHELL 写了一个 ...
随机推荐
- PHP即时实时输出内容
一般情况下,PHP都是将整个页面全部执行完成后,才会把要输出的内容发送回客户端. for ($i = 0; $i < 10; $i++) { echo $i; sleep(1); } 这段代码会 ...
- ActiveX控件的注册和反注册
原文转自 https://blog.csdn.net/piaopiaopiaopiaopiao/article/details/41649495 ActiveX控件,需要注册之后才能使用. 注意:注册 ...
- jQuery的淡入和淡出简单介绍
在jQuery中的一些特效中,可以通过四个方法来实现元素的淡入淡出,这四个方法分别是:fadeIn().fadeOut().fadeToggle() 以及 fadeTo(),下面为分别为大家介绍各个方 ...
- BASIS小问题汇总1
try to start SAP system but failed 2019-04-04 Symptom: when i tried to start SAP system, using the c ...
- iOS开发-NSArray
忙了一上午,解决了几个bug,现在终于抽出来一点时间喝点水休息下, 想着系列这么浩大的一个工程,才刚刚开始写,不能断了,就跟写小说一样,既然是系列,那么就需要不停更... 好吧. 简单的说说iOS开发 ...
- Windows Server 2012 R2上安装.Net4.6.1出错
在Windows Server 2012 R2上安装.Net4.6.1时提示“你需要先安装对应于 KB2919355 的更新,然后才可在……”解决方式: 在官网下载更新包,下载地址:https://w ...
- Spring之AOP原理、代码、使用详解(XML配置方式)
Spring 的两大核心,一是IOC,另一个是AOP,本博客从原理.AOP代码以及AOP使用三个方向来讲AOP.先给出一张AOP相关的结构图,可以放大查看. 一.Spring AOP 接口设计 1.P ...
- (一)react-native开发系列之Mac开发环境配置
写在前面 在开始之前,先说下选择react-native的背景原因 最近一年来,公司为了节省开发成本,以及降低维护成本,指派我开始做起前端开发app的工作,我和公司的小伙伴们就开始了漫长的app开发之 ...
- [LeetCode] 300. 最长上升子序列 ☆☆☆(动态规划 二分)
https://leetcode-cn.com/problems/longest-increasing-subsequence/solution/dong-tai-gui-hua-she-ji-fan ...
- lumen添加自定义异常
在公用工具类写异常类 <?php namespace Brady\Tool\Exception; use Brady\Tool\Constant\ErrorMsg; use \Exception ...