问题记录:/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
相关推荐
IMPYLH1 小时前
Linux 的 yes 命令
linux·运维·服务器·数据库·bash
诸神缄默不语3 小时前
Linux shell脚本教程
linux·bash·shell·sh
承渊政道1 天前
【MySQL数据库学习】(MySQL库的操作和表的操作)
数据库·学习·mysql·ubuntu·bash·数据库架构·数据库系统
IMPYLH2 天前
Linux 常用命令列表
linux·运维·服务器·bash
承渊政道2 天前
【MySQL数据库学习】(MySQL数据库基础)
数据库·学习·mysql·ubuntu·bash·数据库架构·数据库系统
IT大白鼠2 天前
Shell基础与Bash常用技巧:命令替换、重定向、管道、作业控制
bash
0x00073 天前
Git Bash 中无法启动 Claude Code ?
开发语言·git·bash
IMPYLH3 天前
Linux 的 users 命令
linux·运维·服务器·前端·数据库·bash
liyoro4 天前
用 Codex + 提示词生成一个快速打开 Ghostty 的 macOS 小工具
macos·shell·ai编程
IMPYLH4 天前
Linux 的 whoami 命令
linux·运维·服务器·bash