2

Recently I experience slow terminal launch time, so I looked into it and found an interesting thing. I am using iTerm on MacBook. There is an option choosing the default behavior:

Login shell or zsh

If I chose "Login shell", it will prompt Last login: Fri Mar 24 17:27:28 on ttys007 (left side below); if I chose "zsh", it won't prompt anything and launch time is very fast (right side below).

difference between login shell and zsh

The default shell I use is zsh, I wonder what's happening inside "login shell" and why it is so slow compared to pure zsh.

2

"Login shell" runs the usual shell (zsh or bash) in login mode, in which the shell processes additional configuration files – such as .zlogin or .bash_profile. Chances are that those files have too many unnecessary commands – try to keep them as lightweight as possible.

You can try running zsh -l and comparing it with regular zsh. (While -l is not a standard "login mode" switch, it's pretty common.)


(Though IMHO, it is a bit odd for a terminal app to even run shells in "login mode" at all… It sort of defeats the whole idea of being able to configure different startup commands.)

3
  • I think your answer helped me out of my problem. There is one line [[ -s "$HOME/.rvm/scripts/rvm" ]] && source "$HOME/.rvm/scripts/rvm" # Load RVM into a shell session *as a function* which after I commented out "login shell" became incredibly fast. Thanks dude
    – xhg
    Mar 24 '17 at 9:44
  • 1
    Yeah, rvm was horribly slow the last time I tried it as well. But in general, anything that defines functions ought to go to the main config file – .zshrc or .bashrc – not to the "login" one.
    – user1686
    Mar 24 '17 at 9:49
  • thx for your advice. I cannot remember why it is there
    – xhg
    Mar 24 '17 at 9:50

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.