在加载zsh时出现终端错误("...command not found: ^M")

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”。
我发现有关字符行间距未正确处理的内容(对我来说很困惑),但我并没有完全理解它,并且解决方向不够清晰。
非常感谢您的帮助!
1个回答

7

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

Windows风格的文本文件使用CR-LF对标记其行尾;CR(回车符)通常表示为^MCtrl-M)。

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

zsh假定使用UNIX风格的行尾,并将CR-LF对视为行尾处的^M字符。

您只需要删除Windows风格的行尾即可。

如果您已安装dos2unix,则可以使用该工具。请务必阅读man页面;与大多数文本过滤器不同,它默认替换其输入文件。

或者您可以使用tr,例如:

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

您可以使用file命令来确定您有哪种类型的文件。虽然它不是100%可靠,但它可能会报告给定文件具有哪种行结束符。
一旦您修复了行结束符,就可以将文件检入Git存储库,然后确保它们仍然正常。
(您可能还想调整.gitconfig设置。默认设置应该没问题。我不知道细节,需要查看文档。)

太棒了 Keith!非常感谢!!运行得非常顺利!! - jasenlew

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接