shell脚本报错:/bin/bash^M bad interpreter No such file or directory

错误描述

具体报错信息如下:

[root@localhost test]# ./test.sh
-bash: ./test.sh: /bin/bash^M: bad interpreter: No such file or directory

主要原因是test.sh是在windows下编辑然后上传到linux系统里执行的。.sh文件的格式为dos格式。而linux只能执行格式为unix格式的脚本。

可以通过vi编辑器来查看文件的format格式。步骤如下:

(1)首先用vim命令打开文件

[root@localhost test]# vim test.sh

(2)在vim命令模式中使用 :set ff 命令

可以看到文件的格式为dos

修改文件format为unix

方法一:使用vi修改文件format

命令:set ff=unix

方法二:直接使用dos2unix命令修改

[root@localhost test]# dos2unix test.sh
dos2unix: converting file test.sh to UNIX format ...
上一篇 Linux下进程及端口查询汇总
下一篇 Linux下tar命令exclude选项排除指定文件或目录
目录
文章列表
1 阿里巴巴Canal Client同步适配器ClientAdapter
阿里巴巴Canal Client同步适配器ClientAdapter
2
Redis 分区
Redis 分区
3
matplotlib之plt.figure
matplotlib之plt.figure
4
Nginx配置SSL采坑总结
Nginx配置SSL采坑总结
5
Spring Boot中application.yml及application.properties常用配置
Spring Boot中application.yml及application.properties常用配置
最新评论
一位WordPress评论者
一位WordPress评论者
2月12日
您好,这是一条评论。若需要审核、编辑或删除评论,请访问仪表盘的评论界面。评论者头像来自 Gravatar。