【问题标题】:Terminal errors on-load zsh ("...command not found: ^M")加载 zsh 时出现终端错误(“...找不到命令:^M”)
【发布时间】:2014-08-04 11:19:47
【问题描述】:

我正在从 oh-my-zsh 转换为 prezto。现在每次打开终端窗口时都会遇到以下错误:

/Users/jasenlew/.zshenv:7: command not found: ^M
/Users/jasenlew/.zshenv:13: parse error near `\n'
/Users/jasenlew/.zprofile:7: command not found: ^M
/Users/jasenlew/.zprofile:11: command not found: ^M
/Users/jasenlew/.zprofile:80: parse error near `\n'
/Users/jasenlew/.zshrc:7: command not found: ^M
/Users/jasenlew/.zshrc:15: parse error near `\n'
/Users/jasenlew/.zlogin:7: command not found: ^M
/Users/jasenlew/.zlogin:15: command not found: ^M
/Users/jasenlew/.zlogin:9: command not found: ^M
/Users/jasenlew/.zlogin:12: command not found: then^M
/Users/jasenlew/.zlogin:16: command not found: ^M
/Users/jasenlew/.zlogin:21: parse error near `\n'
/Users/jasenlew/.zlogin:zcompile:13: can't open file: /Users/jasenlew/.zcompdump^M^M
/Users/jasenlew/.zlogin:14: command not found: fi^M

我已经删除了 oh-my-zsh,并按照此处的 repo/说明安装了 prezto:https://github.com/hackreactor-labs/prezto

我做了一些谷歌搜索并尝试了一些解决方案,但都没有奏效,包括将我的 .gitconfig 文件中的一行从“autocrlf = true”更改为“autocrlf = false”。

我发现了一些关于字符行间距没有被正确处理的问题(让我感到困惑),但我并没有完全理解它,解决的方向也很模糊。

再次感谢您的帮助!

【问题讨论】:

    标签: shell terminal zsh zshrc oh-my-zsh


    【解决方案1】:

    您的 /Users/jasenlew/.z* 文件具有 Windows 样式的行尾,zsh 无法识别。

    Windows 风格的文本文件的行尾标有 CR-LF 对; CR(回车)通常表示为^M (Ctrl-M)。

    UNIX 风格的文本文件的行尾仅用 LF(换行)字符标记。

    zsh 采用 UNIX 样式的行尾,并将 CR-LF 对视为行尾的 ^M 字符。

    您只需删除 Windows 样式的行尾。

    如果你安装了dos2unix,你可以使用它。请务必阅读手册页;与大多数文本过滤器不同,它默认替换其输入文件。

    也可以使用tr,例如:

    tr -d '\r' < filename > filename.tmp
    # check filename.tmp to make sure it's correct
    mv filename.tmp filename
    

    您还可以使用file 命令来确定您拥有的文件类型。它不是 100% 可靠的,但它可能会报告给定文件的行尾类型。

    修复行尾后,您可以将文件重新检入您的 Git 存储库,然后确保它们仍然正常。

    (您可能还想调整您的.gitconfig 设置。默认设置应该没问题。我不知道我脑海中的细节。)

    【讨论】:

    • 太棒了基思!非常感谢!!像魅力一样工作!
    猜你喜欢
    • 2021-10-23
    • 2011-06-24
    • 2021-12-14
    • 2021-12-17
    • 2016-08-27
    • 2017-09-29
    • 2016-06-02
    • 2019-11-17
    • 1970-01-01
    相关资源
    最近更新 更多