Boston Linux & UNIX was originally founded in 1994 as part of The Boston Computer Society. We meet on the third Wednesday of each month, online, via Jitsi Meet.

BLU Discuss list archive


[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Discuss] What the use of .bashrc



> From: discuss-bounces+blu=nedharvey.com at blu.org [mailto:discuss-
> bounces+blu=nedharvey.com at blu.org] On Behalf Of Glenn Hoffman
> 
> I'm teaching an Introduction to Linux/Unix class at UMass/Boston. I've just
> told the class about the different type of shells (login, interactive non-login
> in, non-interactive) and the startup files for each. I've never been able to
> give a class a good reason for the existence of .bashrc, since I have never
> used it myself. What's the reason for a separate startup file for a non-login
> interactive shell?

The answer here is different from OS to OS (behavior is different on redhat versus solaris, etc).

The true answer is to read the bash man page, and then read the startup scripts in the order they execute - /etc/profile /etc/profile.d /etc/bashrc ~/.bash_profile ~/.bashrc and understand them.  You'll see that for login shells, bash executes profile, and for non-login shells, it executes bashrc.  But somebody decided it would be a good convention (redhat) to source bashrc from profile.  That way, bashrc gets executed for every single instance of bash, while bash_profile only gets executed for login shells.

So when you're doing something like appending the path
	export PATH=$PATH:/foo/bar/bin
That's something you want to do in .bash_profile, so it doesn't get infinitely longer every time you launch a new xterm or execute a bash script, or any other non-login invokations of bash as a child of the login bash.

But many times people will do things like launch a VNC session, and from that point onward, all their terminals are xterm or whatever.  So the .bash_profile is never run again.  So you stick anything you want *always* sourced into .bashrc
	alias ll='ls -l'
	export JAVA_HOME=/usr/local/java-1.6
This would be a good entry for .bashrc, because it's safe to execute again and again, no matter how many children of children deep you go.




BLU is a member of BostonUserGroups
BLU is a member of BostonUserGroups
We also thank MIT for the use of their facilities.

Valid HTML 4.01! Valid CSS!



Boston Linux & Unix / webmaster@blu.org