2026-04-02 23:12:36 +08:00

22 lines
868 B
Markdown
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

---
title: bash脚本格式问题
createTime: 2023/06/26 12:11:42
tags:
- linux
categories:
- 随记
---
运行 bash 脚本时报错`-bash: ./create-lxc-template.bash: /bin/bash^M: bad interpreter: No such file or directory`
这个错误通常是由于在 Windows 环境下编辑的脚本文件,其中包含了 Windows 特有的换行符CRLF即“\r\n”而不是 Unix/Linux 环境使用的换行符LF即“\n”
使用`sed -i 's/\r//' file.bash`将文件中的 CRLF 替换为 LF。您可以使用以下命令将文件中的 CRLF 替换为 LF
也可以使用 dos2unix 工具将文件转换为 Unix 格式。可以使用 dos2unix 工具将文件从 Windows 格式转换为 Unix 格式。如果您的系统中没有安装 dos2unix 工具,请使用以下命令安装:
```bash
sudo apt install dos2unix
dos2unix file.bash
```