Operating System - HP-UX
1828474 Members
2585 Online
109978 Solutions
New Discussion

Re: Where is PATH variable set?

 
Gary Cooper_1
Esteemed Contributor

Where is PATH variable set?

When I log in, my PATH variable has 27 different path components. Many of these, I can easily trace to things like my .profile, but others, I am having problems finding where they are set up.

Does anyone know of a tool or have a script that will tell me where all of my PATH components are set?

Thanks,

Gary
10 REPLIES 10
Chris Wilshaw
Honored Contributor

Re: Where is PATH variable set?

The default path is set in the file /etc/PATH.

Your local profile then makes changes to this (as you've already seen).
Gary Cooper_1
Esteemed Contributor

Re: Where is PATH variable set?

Thanks for the reply, Chris - I'm impressed at how quickly I got a response - 2 minutes from posting!

Unfortunately, the PATH components I'm looking for are application level paths that aren't set in /etc/profile.

Thanks,

Gary
Thierry Poels_1
Honored Contributor

Re: Where is PATH variable set?

hi,

options enough:
- /etc/PATH
- modified in /etc/profile
- modified again in $HOME.profile
...

regards,
Thierry.
All unix flavours are exactly the same . . . . . . . . . . for end users anyway.
Muthukumar_5
Honored Contributor

Re: Where is PATH variable set?

/etc/profile will set PATH with script lines of,

# Set the default paths - Do NOT modify these.
# Modify the variables through /etc/PATH and /etc/MANPATH

PATH=/usr/bin:/usr/ccs/bin:/usr/contrib/bin:/usr/contrib/Q4/bin:/opt/perl/bin:/opt/java1.4/bin
MANPATH=/usr/share/man:/usr/contrib/man:/usr/local/man




# Insure PATH contains either /usr/bin or /sbin (if /usr/bin is not available).

if [ ! -d /usr/sbin ]
then
PATH=$PATH:/sbin

else if [ -r /etc/PATH ]
then

# Insure that $PATH includes /usr/bin . If /usr/bin is
# present in /etc/PATH then $PATH is set to the contents
# of /etc/PATH. Otherwise, add the contents of /etc/PATH
# to the end of the default $PATH definition above.

grep -q -e "^/usr/bin$" -e "^/usr/bin:" -e ":/usr/bin:"\
-e ":/usr/bin$" /etc/PATH
if [ $? -eq 0 ]
then
PATH=`cat /etc/PATH`
else
PATH=$PATH:`cat /etc/PATH`
fi
fi
fi

hth.

export PATH
Easy to suggest when don't know about the problem!
Muthukumar_5
Honored Contributor

Re: Where is PATH variable set?

PATH variable can be changed on /etc/PATH file, /etc/profile, $HOME/.profile that is all. And changes to that shell will not effect other shell without using the any of the three.
Easy to suggest when don't know about the problem!
Ravi_8
Honored Contributor

Re: Where is PATH variable set?

Hi,

the system PATH is set in .profile file

for any application you installed, it creates a directory /opt//bin

open the .profile file (using vi) and at the of PATH line add the application bin path(i.e some thing like this, PATH=/sbin:/usr/bin:/opt//bin

save and close the file

logout and login again
never give up
Gary Cooper_1
Esteemed Contributor

Re: Where is PATH variable set?

Thanks for the very prompt responses guys.

However what I was getting at was some sort of tool/script or debug switch that I could use which when run would (say) create a PATH log file along the lines of:

/etc/profile: /usr/bin
/etc/profile: /usr/contrib/bin
/home/: .
/opt/cgs/etc/profile: /opt/cgs/bin

I've now found where the part of the PATH variable that I'm interested in is set - /opt/cgs/etc/profile, so my immediate problem is over.

Thanks again,

Gary
Peter Godron
Honored Contributor

Re: Where is PATH variable set?

Gary,
I think the only way you could get this list of where individual parts of the PATH are set is by doing a echo of $PATH at the beginning and end of each files (/etc/profile.../.login etc.) and comparing the differences added in each file.
Sorry
Bill Hassell
Honored Contributor

Re: Where is PATH variable set?

The PATH variable is just another variable so any program or script can add or completely replace the PATH variable. It is quite common for some applications to add their own setup to /etc/profile, possibly in the form of a 'sourced' script (ie, . /opt/cgs/etc/profile) or even by the application itself in it's own startup script. You fastest way to find the culprit is to echo $PATH at the start of /etc/profile and $HOME/.sh_profile, and also at the end of these files. If the value was changed by the exit point, something inside the script changed it.

I'm not a fan of long PATH variables at all. They can degrade startup performance but most important, they are a source of potential hacking. Every entry in /etc/PATH as well as any changes to $PATH should be verified that it is valid and necessary. I've attached a script that looks at /etc/PATH and then looks at the current value of $PATH. It will put out error messages for directory paths that do not exist, current working directory, or worse, are world-writable.


Bill Hassell, sysadmin
Gary Cooper_1
Esteemed Contributor

Re: Where is PATH variable set?

Thanks guys.

I must say, that's what I've done in the past - embed echo statements in .profile, etc. It is pretty cumbersome though.

Thanks for the script Bill, I'll have a look at that.

Cheers,

Gary