Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

Few questions:

  • What is a distinct purpose of .profile and .zshrc?
  • What gets called first when the shell comes to life?
share|improve this question

1 Answer 1

up vote 2 down vote accepted

~/.profile is only loaded when running zsh in sh compatibility mode, otherwise it reads .zprofile, as well as .zshrc for interactive and .zlogin for login shells.

Their purpose develops from when they're loaded. As .zshrc is loaded for interactive shells, set the aliases etc. you expect in such cases there.

.profile has the additional property that it's loaded by several other shells as well (e.g. bash, unless it finds something more specific; or ksh) in one way or another, so you can store configuration for multiple shells in this file.

Relevant excerpts from man zshall, emphasis mine:

STARTUP/SHUTDOWN FILES
Commands are first read from /etc/zshenv; [...]

Commands are then read from $ZDOTDIR/.zshenv. If the shell is a login shell, commands are read from /etc/zprofile and then $ZDOTDIR/.zprofile. Then, if the shell is interactive, commands are read from /etc/zshrc and then $ZDOTDIR/.zshrc. Finally, if the shell is a login shell, /etc/zlogin and $ZDOTDIR/.zlogin are read.

COMPATIBILITY
Zsh tries to emulate sh or ksh when it is invoked as sh or ksh respectively; [...]

The usual zsh startup/shutdown scripts are not executed. Login shells source /etc/profile followed by $HOME/.profile. If the ENV environment variable is set on invocation, $ENV is sourced after the profile scripts. The value of ENV is subjected to parameter expansion, command substitution, and arithmetic expansion before being interpreted as a pathname. Note that the PRIVILEGED option also affects the execution of startup files.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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