终端错误on-load zsh("...找不到命令:^ M")

jas*_*lew 2 shell terminal zsh zshrc oh-my-zsh

我正在从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
Run Code Online (Sandbox Code Playgroud)

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

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

我找到了一些东西(让我很困惑)关于字符行间距没有被正确处理,但是没有完全理解它,并且解决的方向是模糊的.

再次感谢您的帮助!

Kei*_*son 6

您的/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
Run Code Online (Sandbox Code Playgroud)

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

一旦修复了行结尾,就可以将文件检查回Git存储库,然后确保它们仍然正常.

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