[oclug] set $PATH

Joe Burpee jeb at burkby.com
Fri Jul 11 10:11:38 EDT 2003


On Fri, Jul 11, 2003 at 08:53:09 -0400, Bart Trojanowski wrote:
> So how about something like this:
> 
> ----- .bash_profile -----
> 
> export BASH_PROFILE_READ=`date +%s`
> 
> # ... do all the .bash_profile stuff now ...
> 
> ----- end -----
> 
> Now, if .bash_profile is read it will export the time it was read.
> 
> ----- .bash_profile -----
> 
> BASH_PROFILE_TIME=`stat -c%Y ~/.bash_profile`
> 
> if [ ${BASH_PROFILE_TIME} -gt ${BASH_PROFILE_READ-0} ] ; then
> 	. ~/.bash_profile
> endif
> 
> # ... do all the .bashrc stuff now ...
> 
> ----- end -----
> 
> Each time you start a new shell .bashrc gets run.
 
I don't want to split hairs, but this is not strictly true.  It does
normally apply to interactive shells (subject to `--norc', invocation as
`sh', etc.), and also to non-interactive ones subject to ENV, BASH_ENV,
`-i', etc.  (See man bash.)

I've probably distorted the meaning of your above sentence.  But I just
want to note that, on RH at least, BASH_ENV is set in ~/.bash_profile
(and exported of course, making it available to subshells).  The
`profile' is intended as a one-time precursor to all the `rc'
invocations.

> At this time there
> is a test to make sure that .bash_profile was read at least once, and if
> .bash_profile was modified it will be read again.
 
... assuming you actually want to do this, prior to your next login.

> Thoughts?
 
This is fun stuff, but I'm not sure I see the point.  Brenda explained
the purpose of the `profile' and `rc' files in a manner that is
consistent with the documentation.  I realize that shell initialization
is convoluted and somewhat archaic.  Moreover I'm a great lover of
kluges and hacks, provided there is a purpose.  But personally I find
the appropriate use of a login shell, at login time, simpler and
clearer.

> Should .bashrc blindly source .bash_profile and have .bash_profile doing
> the checks?
 
IMO no.  But if you could explain why you want to do these things, I'm
willing to be convinced.  ;-)

Joe



More information about the OCLUG mailing list