Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Zsh show fail every time when I open my terminal

I'm using a Mac with OS X Yosemite and Zsh. By accident,I delete the content of three files below: .bashrc .bash_profile .profile After that ,when I open my terminal. The Zsh will show fail under the last login information,it confused me ,and I want to know why.

like image 849
helloworld Avatar asked Mar 26 '15 15:03

helloworld


2 Answers

You might want to look at a duplicate question: Zshell starts up with exit status of 1 after uninstalling RVM

It has an answer that solved the issue for me:

I found a .zlogin file on my system that contained some rvm-related code. I've deleted the code, and the problem is solved!

like image 150
fjuan Avatar answered Oct 25 '22 22:10

fjuan


Zsh (by default) doesn't read from .bashrc, .bash_profile, or .profile, so the contents of these files shouldn't matter. You also didn't mention which .bashrc, .bash_profile, and .profile were erased… These files exist in both your /Users/username directory and /etc. The files sourced by zsh at startup are listed in the OS X zsh man page (man zsh in a terminal) under "STARTUP/SHUTDOWN FILES". The only reason it would call one of the previously mentioned files is if they were explicitly sourced in one of the default files.

My suggestions:

  • 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.

Hope this helps.

like image 44
Dustin Wheeler Avatar answered Oct 25 '22 22:10

Dustin Wheeler