Linux sh文件报错: cannot execute: required file not found

📅 2026/7/5 3:32:32 👁️ 阅读次数 📝 编程学习
Linux sh文件报错: cannot execute: required file not found

脚本文件中存在不可见的 Windows 换行符(CRLF)
如果你在 Windows 下编辑脚本并上传到 Linux,\r\n 会导致整个 shebang 行变成 #!/bin/bash\r,系统找不到带 \r 的文件名。

解决方法:

cat -A start_redis.sh查看,如果每行末尾出现^M$就是 CRLF。

安装并运行 dos2unix your.sh 转换。