Login Scripts
Mac OS X provides support for login scripts and environment property lists to allow you to set environment variables and aliases that are automatically set whenever you run a new shell. There are three ways to do this:
Bourne shell (bash, zsh, and so on):
To persistently set environment variables and add aliases, you can add the appropriate alias, variable assignment, and export commands to the following files:
~/.profile—executed automatically for all login shells.
~/.bash_profile—similar to .profile, but only runs for bash login shells.
~/.bashrc and ~/.zshrc—executed automatically for all non-login bash or zsh shells (when you explicitly type bash or zsh on the command line or run a script that starts with #!/bin/bash or #!/bin/zsh).
You may also find it useful to create a .bashrc file that sources your .profile file. For example:
. $HOME/.profile
Sourcing is described in more detail in “Subroutines, Scoping, and Sourcing.”
C shell (csh, tcsh, and so on):
To persistently set environment variables and add aliases, you can add the appropriate alias, set, and setenv commands to the following files:
~/.login—automatically executes for all login shells.
~/.cshrc—automatically executes for all non-login shells (when you explicitly type bash on the command line or run a script that starts with #!/bin/csh or #!/bin/tcsh).
You may also find it useful to create a .cshrc file that sources your .login file. For example:
source $HOME/.login
Sourcing is described in more detail in “Subroutines, Scoping, and Sourcing.”
All login shells:
To persistently set environment variables, add them to the ~/.MacOSX/environment.plist property list file. For more information, see Runtime Configuration Guidelines.