I've used a number of different *nix-based systems of the years, and it seems like every flavor of Bash I use has a different algorithm for deciding which startup scripts to run. For the purposes of tasks like setting up environment variables and aliases and printing startup messages (e.g. MOTDs), which startup script is the appropriate place to do these?
What's the difference between putting things in .bashrc
, .bash_profile
, and .environment
? I've also seen other files such as .login
, .bash_login
, and .profile
; are these ever relevant? What are the differences in which ones get run when logging in physically, logging in remotely via ssh, and opening a new terminal window? Are there any significant differences across platforms (including Mac OS X (and its Terminal.app) and Cygwin Bash)?
Classically,
~/.profile
is used by Bourne Shell, and is probably supported by Bash as a legacy measure. Again,~/.login
and~/.cshrc
were used by C Shell - I'm not sure that Bash uses them at all.The
~/.bash_profile
would be used once, at login. The~/.bashrc
script is read every time a shell is started. This is analogous to/.cshrc
for C Shell.One consequence is that stuff in
~/.bashrc
should be as lightweight (minimal) as possible to reduce the overhead when starting a non-login shell.I believe the
~/.environment
file is a compatibility file for Korn Shell.