Bash aka The Solution for Everything — The ''Special Files''
These quick tips will help you understand how bash runs startup files.
Join the DZone community and get the full member experience.Join For Free
In bash, the shell reads one or more startup files. Here's the details about what's what and which is run when.
- /etc/profile is executed automatically at login.
- The file from the list of ~/.bash_profile, ~/.bash_login, or ~/.profile are then executed at login.
- ~/.bashrc is executed by every non-login shell, but if sh is used to invoke bash it reads the $ENV for POSIX compatability.
For reference, the ~ symbol is used in place of the user directory. One way to check this out yourself is to change directory to ~ with a
cd ~ in the shell, then type
pwd which will give the current directory. You'll find that it is something like
/Users/adron where instead of my name it'd be your user name.
When invoking the shell, you can also skip the ~/.bashrc or otherwise change the way bash starts up with the following options.
bash --init-file theFileToUseInsteador
--rcfileinstead of ~/.bashrc.
bash --norcwhich is similar to invoking with
sh, which will use $ENV.
bash --noprofilewill prevent /etc/profile or any other personal startup files. This will provide a pretty baseline bash shell for use.
Until next time, happy bash code thrashing!
Published at DZone with permission of Adron Hall, DZone MVB. See the original article here.
Opinions expressed by DZone contributors are their own.