每次打开终端时,Zsh都会显示失败

7

我正在使用带有OS X Yosemite和Zsh的Mac电脑。 不小心删除了以下三个文件的内容: .bashrc .bash_profile .profile 之后,当我打开终端时, Zsh将在上次登录信息下显示失败,这让我感到困惑,并且我想知道原因。


“Fail” 是什么意思? - svlasov
“fail”是在最后一次登录信息下面的一个单词。就像你输入了一个错误的命令一样。 - helloworld
2个回答

8
您可能想看一下一个重复的问题:Zshell在卸载RVM后启动时的退出状态为1 它有一个答案解决了我的问题:

我在系统上找到一个.zlogin文件,其中包含一些与rvm相关的代码。我删除了这些代码,问题解决了!


5
默认情况下,Zsh不会读取.bashrc.bash_profile或者.profile文件的内容,因此这些文件的内容并不重要。您也没有提到删除了哪个.bashrc.bash_profile.profile文件... 这些文件存在于您的/Users/username目录和/etc目录中。在启动时,Zsh源文件列表在OS X zsh man page(在终端中使用 man zsh 命令)的“STARTUP/SHUTDOWN FILES”部分列出。只有当它们被明确地在默认文件中source时,才会调用先前提到的文件之一。

我的建议:

  • Check the contents of /etc/zshenv (this is the only zsh-specific file in my etc directory). Mine has only the following:

    # system-wide environment settings for zsh(1)
    if [ -x /usr/libexec/path_helper ]; then
      eval `/usr/libexec/path_helper -s`
    fi 
    
  • Can you log in at all using zsh? If not, can you log in using another shell? You can do this in the OS X Terminal.app by going to Preferences -> General and changing the option for "Shells open with:" from "Default login shell" to Command (fill in another shell, i.e., /bin/bash or /bin/sh). If you can log in with any shell, try the following solution from this question:

    Looking for the error

    All shell output goes to the terminal, so you could just redirect it when starting it. As you are looking for error messages during initialisation, I'd suggest the following procedure:

    1. Disable the problematic configurations
    2. Open a terminal
    3. Check the value of SHLVL: echo $SHLVL
    4. Re-enable the configurations
    5. Start a new z-shell from within the running shell with zsh 2> zsh-error.log, this redirects stderr to the file 'zsh-error.log'.
    6. Check the value of SHLVL again. If it is bigger then previous value then exit the current shell (exit). (Explanation below)
    7. Have a look at 'zsh-error.log' in the current directory.

    If 'zsh-error.log' does not show anything, you may want to run zsh -x 2> zsh-error.log in step 5 instead. This provides a complete debug output of anything zsh does. This can get quite huge.

    As the answer suggests, those logs can get enormous if you are sourcing man files at startup. Just a bare shell should result in a reasonably small log file.

  • Finally, you can retrieve a list of all the files sourced by zsh on startup by running zsh -o sourcetrace.

希望这对您有所帮助。

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