问题记录:/bin/bash^M: 解释器错误:没有那个文件或目录(bad interpreter: No such file or directiry)

问题描述

运行脚本时报错如下:

/bin/bash^M: 解释器错误:没有那个文件或目录(bad interpreter: No such file or directiry)

原因分析

脚本文件在windows下编辑过,windows下行结尾是\n\r,而Linux下则是\n

使用cat-A filename命令可以看到结尾\r字符被显示为^M

解决方案

在终端shell输入如下命令,将脚本文件中的行尾\r替换为空白

bash 复制代码
sed -i 's/\r$//' xxx.sh
相关推荐
归叶再无青5 天前
web服务安装部署、性能升级等(Apache、Nginx)
运维·前端·nginx·云原生·apache·bash
归叶再无青5 天前
企业级web服务(Tomcat开源web应用服务器)
运维·前端·开源·tomcat·bash
EverydayJoy^v^6 天前
Linux Shell 高级编程(3)——awk
linux·运维·shell
chao_7896 天前
构建start_app.sh,实现快速启动项目
python·bash·终端·前后端
笨笨D幸福6 天前
应用程序重定向技术(Shim)
bash·scoop·shim
xuchaoxin13757 天前
bash@bash帮助命令help@bash命令可用选项设置@bash -c@set命令@set --
bash
ol木子李lo8 天前
Linux 命令备忘录
linux·运维·服务器·windows·编辑器·ssh·bash
dingdingfish9 天前
Bash学习 - 第10章:Installing Bash
bash·make·shell·install·configure·5.3
dingdingfish9 天前
Bash学习 - 第8章:Command Line Editing,第3节:Readline Init File
bash·init·bind·readline
dingdingfish10 天前
Bash学习 - 第8章:Command Line Editing,第6-8节:Programmable Completion
bash·shell·completion·complete·compgen·compopt