Click to See Complete Forum and Search --> : $PATH problem


Raw_recruit
06-30-2001, 10:49 PM
I can't find where in the manuals that tells how $PATH is initially
set from a boot-up and then also what other scripts from then on
which might also be modifying $PATH.

The problem I'm trying to clear up is that my $PATH has got
several duplicate entries and I want to clean it up. But, I don't
know 'who' all is setting it up and 'who' all is making modifications
along the way.

I have looked in /etc/profile which contains the following:

if ! echo $PATH | /bin/grep -q "/usr/X11R6/bin" ; then
$PATH="$PATH:/usr/X11R6/bin"
fi

Also I added the following to /etc/profile:

PATH=$PATH:/usr/java/jdk1.3.1/bin

My question is, if /etc/profile is the first script to execute which
sets $PATH, then WHY is it testing it for the presence of a path
name if it isn't expecting $PATH to ALREADY have been set to
some value????? If there were to be something there,
(viz. "/usr/X11R6/bin") then /etc/profile could not have been the
first script to set $PATH.

The following is in my /root/.bash_profile (I am having this
symptom while logged in as root):

PATH=/usr/local/sbin:/usr/sbin:/sbin:$PATH:$HOME/bin

Also, I found PATH getting the following from /etc/rc.sysinit :

PATH=/bin:/sbin:/usr/bin:/usr/sbin

From boot-up, which script is the first to set up the default $PATH? I'm guessing /etc/rc.sysinit

From log-in, what other scripts may or will be run to modify the
default? Again, I'm guessing first /etc/profile followed by /$HOME/.bash_profile.

Are there others?

It is looking like perhaps one or more of
these scripts are being executed twice due
to paths showing up twice in the final $PATH.

I'm using RedHat 7.1

Thanks
Doug

:eek: :eek: :mad: :eek: :eek: :eek: :eek: :eek:

EscapeCharacter
06-30-2001, 10:56 PM
well if you look lower down in /etc/profile you'll see a line like export $PATH, export is what sets PATH

Raw_recruit
06-30-2001, 11:13 PM
Sorry EscapeCharacter, but I believe you misunderstood my question. I know about what "export" does. Export only makes valid the assignment statement, i.e. "PATH="
I'm looking for ALL the scripts that set or
modify the $PATH variable.
I am getting duplicate path entries in the
colon separated list of path names in my
$PATH. I'm trying to discover which script is causing the duplicate entries.
Doug :rolleyes:

Linuxcool
07-01-2001, 12:24 AM
According to the bash man page:
Login shells:
On login (subject to the -noprofile option):
if /etc/profile exists, source it.

if ~/.bash_profile exists, source it,
else if ~/.bash_login exists, source it,
else if ~/.profile exists, source it.

On exit:
if ~/.bash_logout exists, source it.

Non-login interactive shells:
On startup (subject to the -norc and -rcfile options):
if ~/.bashrc exists, source it.

Non-interactive shells:
On startup:
if the environment variable ENV is non-null, expand
it and source the file it names, as if the command
if [ "$ENV" ]; then . $ENV; fi
had been executed, but do not use PATH to search
for the pathname. When not started in Posix mode, bash
looks for BASH_ENV before ENV.

So, it depends on what type of shell it is started as.

bdl
07-01-2001, 01:59 AM
Originally posted by Raw_recruit:
<STRONG>I'm looking for ALL the scripts that set or
modify the $PATH variable.
I am getting duplicate path entries in the
colon separated list of path names in my
$PATH. </STRONG>

Ok so why not just set an absolute path in your ~/.bash_profile or ~/.profile?? Leave out the "$PATH" assignment in your personal shell init and set only the path you want.

bdg1983
07-01-2001, 06:52 AM
As bdl suggested.

Instead of

PATH=$PATH:/usr/local/sbin:/usr/sbin

try

PATH=/usr/local/sbin:/usr/sbin...

That way $PATH sorta gets reset to null.