3

我正在从 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/instructions 安装了 prezto:https ://github.com/hackreactor-labs/prezto 。

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

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

再次感谢您的帮助!

4

1 回答 1

7

您的/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设置。默认设置应该没问题。我不知道我脑海中的细节。)

于 2014-06-13T20:28:28.870 回答