Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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
up vote 4 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:

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.

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
// , Would you be willing to add an example? Say both .profile and .zprofile are present, but zsh is being run in compatibility mode. – Nathan Basanese Jun 14 '15 at 15:38

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .