.. _intro_zsh_startup_files:

Startup Files
=============

There are five startup files that :literal:`zsh` will read commands from:

.. code-block:: text
   :caption: Five startup files
   :name: startup_files_list

   $ZDOTDIR/.zshenv
   $ZDOTDIR/.zprofile
   $ZDOTDIR/.zshrc
   $ZDOTDIR/.zlogin
   $ZDOTDIR/.zlogout

If :literal:`ZDOTDIR` is not set, then the value of :literal:`HOME` is used; this is the usual case.

:literal:`.zshenv` is sourced on all invocations of the shell, unless the :literal:`-f` option is set.  It should contain commands to set the command search path, plus other important environment variables. :literal:`.zshenv` should not contain commands that produce output or assume the shell is attached to a tty.

:literal:`.zshrc` is sourced in interactive shells.  It should contain commands to set up aliases, functions, options, key bindings, etc.

:literal:`.zlogin` is sourced in login shells.  It should contain commands that should be executed only in login shells. :literal:`.zlogout` is sourced when login shells exit. :literal:`.zprofile` is similar to :literal:`.zlogin`, except that it is sourced before :literal:`.zshrc`. :literal:`.zprofile` is meant as an alternative to :literal:`.zlogin` for ksh fans; the two are not intended to be used together, although this could certainly be done if desired. :literal:`.zlogin` is not the place for alias definitions, options, environment variable settings, etc.; as a general rule, it should not change the shell environment at all.  Rather, it should be used to set the terminal type and run a series of external commands (\ :literal:`fortune`, :literal:`msgs`, etc).
