Wednesday, August 14, 2013

A little about bash Profiles


There are a number of configuration startup files in your home directory that you can edit to make your configurations permanent. You can also edit these files to specify commands to be run whenever you first log in, log out, or start a new shell.

When you use bash, and the first time you log in, bash checks to see if '/etc/profile' exisits, and if so, it executes the commands in this file. This file is a generic, system-wide startup file. Next, bash checks '~/.bash_profile', which is a hidden file in your home dir. This file holds all the commands you want to run every time yuo log in.

For all new shells after you've logged in (that is, all but the "login shell"), bash reads and executes the commands in the `.bashrc' file in your home directory. Commands in this file run whenever a new shell is started except for the login shell. You can put all of your own customizations in ".bashrc" file, and put the following line in your ".bash_profile":

if [ −f ~/.bashrc ]; then . ~/.bashrc; fi

This way all your commands will be run both at log in and for all subsequent shells. Any customizations before this line in `.bash_profile' run only when you log in.

No comments: