问题记录:/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
相关推荐
SEO_juper2 天前
Bash 交叉验证 robots.txt 和 sitemap:两个文件自相矛盾,页面永远收录不了
开发语言·python·node.js·json·bash
sbjdhjd2 天前
从污点追踪断点到 PHP-FPM 请求队列:HIDS PHP WebShell 样本复盘
开发语言·网络安全·数据挖掘·渗透测试·开源·php·shell
无足鸟ICT3 天前
【RHCA+】type命令(判断命令类型)
linux·ssh·bash
ynchyong4 天前
linux中的 sed` 与 `seq`
linux·运维·sed·seq·文本工具
SEO_juper5 天前
Node.js 重定向链检测工具:301 跳了几跳、有没有成环,一次看清
xml·开发语言·python·node.js·json·bash
Shell运维手记5 天前
Shell 结构化命令知识点总结(case、for、while)
运维·microsoft·shell·脚本
云计算练习生5 天前
什么是 Bash?Linux 默认 Shell 的核心功能
linux·操作系统·bash·shell·命令解释器
猫咪很可爱6 天前
MySQL 5.7 备份恢复后函数与存储过程丢失:原因分析与正确备份姿势
数据库·mysql·bug·shell
qetfw7 天前
Linux 文件清理:find、mtime 与安全传参验证
linux·shell·1024程序员节
qetfw7 天前
Bash 函数与流程控制:read、if、for、case 验证
linux·前端·javascript·bash