问题记录:/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
相关推荐
nyf_unknown10 小时前
(vue)将文件夹打成tar包, Git Bash(推荐)具体使用
vue.js·git·bash
conkl2 天前
Linux 零基础万字入门指南(进阶详解版)
linux·运维·服务器·ssh·文件管理·shell·linux基础
青春不流名3 天前
-bash: ll: 未找到命令
开发语言·bash
czhc11400756634 天前
LINUX812 shell脚本:if else,for 判断素数,创建用户
shell
茶之夭夭4 天前
Centos离线部署之Minio
shell
小任今晚几点睡5 天前
防火墙环境下的全网服务器数据自动化备份平台搭建:基于 rsync 的完整实施指南
服务器·shell·rsync·自动化备份
UrbanJazzerati6 天前
PowerShell 自动化实战:自动化为 Git Staged 内容添加 Issue 注释标记 (2)
后端·面试·shell
UrbanJazzerati7 天前
PowerShell 自动化实战:自动化为 Git Staged 内容添加 Issue 注释标记
后端·面试·shell
子洋7 天前
现代化 ls 命令替代工具:EZA
前端·后端·shell
aFakeProgramer8 天前
VRTE 的应用程序部署到Ubuntu上 报错:bash: ./rb_exmd: No such file or directory
bash