找不到 oh-my-zsh 命令:^M

oh-my-zsh Command Not Found: ^M

我正在尝试在 Ubuntu 15 上安装 oh-my-zsh。在 运行 安装脚本

之后
sh -c "$(wget https://raw.github.com/robbyrussell/oh-my-zsh/master/tools/install.sh -O -)"

我有以下以前从未发生过的错误

/home/li-xinyang/.zshrc:3: command not found: ^M
/home/li-xinyang/.zshrc:9: command not found: ^M
/home/li-xinyang/.zshrc:12: command not found: ^M
/home/li-xinyang/.zshrc:16: command not found: ^M
/home/li-xinyang/.zshrc:19: command not found: ^M
/home/li-xinyang/.zshrc:22: command not found: ^M
/home/li-xinyang/.zshrc:25: command not found: ^M
/home/li-xinyang/.zshrc:28: command not found: ^M
/home/li-xinyang/.zshrc:31: command not found: ^M
/home/li-xinyang/.zshrc:34: command not found: ^M
/home/li-xinyang/.zshrc:39: command not found: ^M
/home/li-xinyang/.zshrc:44: command not found: ^M
/home/li-xinyang/.zshrc:47: command not found: ^M
/home/li-xinyang/.zshrc:52: command not found: ^M
/home/li-xinyang/.zshrc:53: command not found: ^M
/home/li-xinyang/.zshrc:55: command not found: ^M
/home/li-xinyang/.zshrc:58: command not found: ^M
/home/li-xinyang/.zshrc:source:59: no such file or directory: /home/li-xinyang/.oh-my-zsh/oh-my-zsh.sh^M
/home/li-xinyang/.zshrc:60: command not found: ^M
/home/li-xinyang/.zshrc:63: command not found: ^M
/home/li-xinyang/.zshrc:70: command not found: ^M
/home/li-xinyang/.zshrc:73: command not found: ^M
/home/li-xinyang/.zshrc:76: command not found: ^M

如何删除 ^M

解决方案是将autocrlf=true设置为autocrlf=false使用下面的命令,

git config --global core.autocrlf true

^M 是回车符 return (CR),Windows 样式的文本行结束符。

我遇到了同样的问题,autocrlf=true 没有解决问题。 在我通过注释掉 ~/.zshrc 中的 git 插件并删除并替换了有问题 ^M 的文件后,问题就解决了。 oh-my-zsh 上的 git 插件似乎有冲突。

    #plugins=(git)

在我的 Mac 运行 dos2unix 中,用于 Oh-My-Zsh 安装的所有文件。总而言之,它类似于下面。我一直重新运行 source ~/.zshrc 以检查安装是否正常,没有任何错误,直到我转换了所有文件,包括二进制文件。

brew install dos2unix
cd /Users/<your user>/.oh-my-zsh
find . -name " *.sh" | xargs dos2unix -f
find . -name " *.zsh" | xargs dos2unix -f
dos2unix -f themes/robbyrussel.zsh-theme
cd 
dos2unix -f .zshrc
source ~/.zshrc

我可以通过在 LF 模式下保存文件 ~/.zshrc 来解决 Ubuntu 中的这个错误。