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 <[email protected]>
Boston Linux and Unix
PGP key id:3BC1EB90
PGP Key fingerprint: 49E2 C52A FC5A A31F 8D66 C0AF 7CEA 30FC 3BC1 EB90
_______________________________________________
Discuss mailing list
[email protected]
http://lists.blu.org/mailman/listinfo/discuss