Boston Linux & UNIX was originally founded in 1994 as part of The Boston Computer Society. We meet on the third Wednesday of each month at the Massachusetts Institute of Technology, in Building E51.

BLU Discuss list archive


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

[Discuss] What the use of .bashrc



On 10/30/2012 07:50 AM, Glenn Hoffman wrote:
> 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?
>
I use the .bashrc all the time. Basically, the ~/.profile is only
executed by the login shell, and not by X. So if you bring up a window
under X (eg Gnome/KDE) it will not execute .profile. the .bashrc file is
executed every time a new shell starts up. Most people I know don't
bother with .profile. Also, you will notice that the standard .profile
has 3 lines:

if [ -f /etc/profile ]; then
    . /etc/profile
fi

And the ~/.bashrc has:
if [ -f /etc/bashrc ]; then
    . /etc/bashrc
fi

In both cases, they test for the existence of the /etc/{profile ||
bashrc}, and then they source it.
It is important to know the difference between sourcing a script and
executing a script.

When you execute a script, a subshell is created, but when the execution
is done it goes away. The environment is passed from parent to child,
but never from child to parent. When you source a shell, the shell is
interpreted in the same environment so any environment changes you make
are preserved. Note that in BASH, the source command is a dot (.) where
in the seasick shells, the source command is 'source'.

-- 
Jerry Feldman <gaf at blu.org>
Boston Linux and Unix
PGP key id:3BC1EB90 
PGP Key fingerprint: 49E2 C52A FC5A A31F 8D66  C0AF 7CEA 30FC 3BC1 EB90





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