Alasdair Macintyre http://www.alasdairmacintyre.co.uk Student and web developer based in York, UK posterous.com Sat, 24 Oct 2009 12:00:00 -0700 Bash: .bashrc, .bash_profile, bash_login and .profile in varying situations http://www.alasdairmacintyre.co.uk/bash-bashrc-bashprofile-and-profile-in-varyin http://www.alasdairmacintyre.co.uk/bash-bashrc-bashprofile-and-profile-in-varyin

On login, bash runs scripts in your home directory depending on a number of factors. Note these scripts don't seem to require being set executable. A summary, as far as I can make out (tested on Debian lenny):

/etc/profile always seems to be run first

/etc/bash.bashrc will be run next for interactive shells (aka not scripts or su -c)

If the shell has been started with the command /bin/sh, bash emulates the older sh shell and runs the ~/.profile script

A ssh login (and presumably also local login) runs ~/.bash_profile , or if it can't be found ~/.bash_login or .profile, if they exist (~/.profile being last)

Graphical terminal emulators usually run ~/.bashrc

The command su username from a shell runs ~/.bashrc

The command su -c "command" username from a shell or script doesn't run any of the scripts (except /etc/profile as always)

The command su -l -c "command" username runs ~/.bash_profile (the -l flag to su emulates a login shell, so the other possibilities mentioned above if .bash_profile doesn't exist)

Permalink | Leave a comment  »

]]>
http://files.posterous.com/user_profile_pics/194325/StillCap0004.jpg http://posterous.com/users/4bmPBDG6O4dr Alasdair Macintyre wombley Alasdair Macintyre