运行shell脚本,错误bash: ./temp.sh: /bin/bash^M: bad interpreter: No such file or directory
来源:互联网 发布:怎么登录淘宝客 编辑:程序博客网 时间:2024/05/08 21:13
今天写了一个shell脚本,然后在执行的时候报错,脚本内容很简单,仅供测试:
- #!/bin/sh
- echo "test shell "
具体报错信息如下:
- [root@localhost test]# ./test.sh
- -bash: ./test.sh: /bin/sh^M: bad interpreter: No such file or directory
由于之前自己对shell不太熟悉,找同事沟通了后了解了原委,主要原因是test.sh是我在windows下编辑然后上传到linux系统里执行的。.sh文件的格式为dos格式。而linux只能执行格式为unix格式的脚本。
我们可以通过vi编辑器来查看文件的format格式。步骤如下:
1.首先用vi命令打开文件
- [root@localhost test]# vi test.sh
2.在vi命令模式中使用 :set ff 命令
可以看到改文件的格式为dos
3.修改文件format为unix
方法一:使用vi修改文件format
命令:set ff=unix
执行完后再通过set ff命令查看文件格式,结果如下:
方法二:直接使用dos2unix命令修改
- [root@localhost test]# dos2unix test.sh
- dos2unix: converting file test.sh to UNIX format ...
修改完后再次执行./test.sh,执行正确:
- [root@localhost test]# ./test.sh
- test shell
0 0
- 运行shell脚本,错误bash: ./temp.sh: /bin/bash^M: bad interpreter: No such file or directory
- 运行shell脚本,错误:-bash: ./xxx.sh: /bin/bash^M: bad interpreter: No such file or directory
- shell脚本异常“bash: ./rebuild.sh: /bin/sh^M: bad interpreter: No such file or directory”
- shell脚本报错:-bash: xxx: /bin/sh^M: bad interpreter: No such file or directory
- shell脚本报错:-bash: xxx: /bin/sh^M: bad interpreter: No such file or directory
- shell脚本报错:-bash: xxx: /bin/sh^M: bad interpreter: No such file or directory
- shell脚本报错:-bash: xxx: /bin/sh^M: bad interpreter: No such file or directory
- shell脚本报错:-bash: xxx: /bin/sh^M: bad interpreter: No such file or directory
- shell脚本报错:-bash: xxx: /bin/sh^M: bad interpreter: No such file or directory
- shell脚本报错:-bash: xxx: /bin/sh^M: bad interpreter: No such file or directory
- 运行sh脚本报错:-bash: ./filename.sh: /bin/bash^M: bad interpreter: No such file or directory
- shell脚本报错 -bash: ./mysql.sh: /bin/bash^M: bad interpreter: No such file or directory
- 笔记:Shell脚本文件报错:-bash: ./xxx.sh: /bin/bash^M: bad interpreter: No such file or directory
- -bash: ./start.sh: /bin/sh^M: bad interpreter: No such file or directory 错误解决方案
- shell脚本报错问题: -bash: ./test.sh: /bin/sh^M: bad interpreter: No such file or directory
- bash脚本:/bin/sh^M:bad interpreter: No such file or directory
- -bash: ./bin/start.sh: /bin/bash^M: bad interpreter: No such file or directory 问题
- shell脚本/bin/bash^M: bad interpreter: No such file or directory
- codeforces round 315 div2 题解
- angular在线验证用户名是否唯一 指令
- C++中删除string对象中的某个字符
- Unity读取XML定制。
- HDU 4967(Handling the Past-线段树维护可持久化栈操作)
- 运行shell脚本,错误bash: ./temp.sh: /bin/bash^M: bad interpreter: No such file or directory
- java内部类
- Android 禁止应用在模拟器上运行的实现
- xcode 静态库
- java中的面向对象的三大基本特征
- 定时器
- ios xml解析
- Python学习----模块
- nginx之基础命令(启动、停止、平滑重启、平滑升级)