- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- setting PATH
Categories
Company
Local Language
Forums
Discussions
Forums
- Data Protection and Retention
- Entry Storage Systems
- Legacy
- Midrange and Enterprise Storage
- Storage Networking
- HPE Nimble Storage
Discussions
Forums
Discussions
Discussions
Forums
Discussions
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
- BladeSystem Infrastructure and Application Solutions
- Appliance Servers
- Alpha Servers
- BackOffice Products
- Internet Products
- HPE 9000 and HPE e3000 Servers
- Networking
- Netservers
- Secure OS Software for Linux
- Server Management (Insight Manager 7)
- Windows Server 2003
- Operating System - Tru64 Unix
- ProLiant Deployment and Provisioning
- Linux-Based Community / Regional
- Microsoft System Center Integration
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Community
Resources
Forums
Blogs
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-27-2004 06:08 AM
05-27-2004 06:08 AM
setting PATH
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-27-2004 06:12 AM
05-27-2004 06:12 AM
Re: setting PATH
I wouldn't worry about it. Instead, you could just figure out exactly what you need in your PATH to run your script and put just those directories into your PATH in your script. Don't worry about what is or isn't there already, just set what you need and run it. It will be cleaner, easier, and much more secure.
JP
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-27-2004 06:14 AM
05-27-2004 06:14 AM
Re: setting PATH
You can do something like this:
#!/usr/bin/sh
pchk(){
if echo $1|sed 's/:/\
/g'|sed 's/$/:/
s/^/:/' |grep :${2}: 1>/dev/null ; then
return 1
else
return 0
fi
}
#-------------------------------------------------------------
export ORACLE_HOME=/home/oracle/orahome
#-------------------------------------------------------------
if [ -z "$SHLIB_PATH" ]; then
export SHLIB_PATH=$ORACLE_HOME/lib
else
if pchk $SHLIB_PATH $ORACLE_HOME/lib ;then
export SHLIB_PATH=$ORACLE_HOME/lib:$SHLIB_PATH
fi
fi
HTH
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-27-2004 06:15 AM
05-27-2004 06:15 AM
Re: setting PATH
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-27-2004 06:19 AM
05-27-2004 06:19 AM
Re: setting PATH
PATH=/usr/bin:/somepath
instead of adding to it...
PATH=${PATH}:/somepath
you won't have to worry about it.
JP
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-27-2004 06:22 AM
05-27-2004 06:22 AM
Re: setting PATH
NEWPATH=path
echo $PATH|grep $NEWPATH >/dev/null
if [ $? != 0 ]
then
export PATH=${PATH}:${NEWPATH}
else
echo "$NEWPATH is already in PATH"
fi
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-27-2004 06:32 AM
05-27-2004 06:32 AM
Re: setting PATH
Anil
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-27-2004 06:30 PM
05-27-2004 06:30 PM
Re: setting PATH
As stated by another JP in this thread:
if you execute myscript by typing 'myscript' or '/.../myscript' or whatever, on exit of the script the PATH variable is unchanged. The script cannot change the PATH variable of its invoking / parent shell.
So one of the first commands of your script should be something like
PATH=/my/additional/path:$PATH or
PATH=$PATH:/my/additional/path.
Keep it simple!
JP
P.S. For completeness: only if you source a script (i.e. '. myscript') the variables are set in the current shell.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-28-2004 05:20 AM
05-28-2004 05:20 AM
Re: setting PATH
entries from a path. I have it in my .profile
so it can add directories that are not already
in the path but refrain from creating duplicates
for directories that were already set by
/etc/profile.
function reduce_path
{
#remove duplicate directories from a path
typeset -i i j
i=0
(
IFS=: #break up path at colon delimiters
for d in $1
do
j=0
while [[ $j -lt $i ]]
do
if [[ $d = ${newpath[$j]} ]]
then
#found a duplicate
break;
fi
j=$j+1
done
if [[ $j = $i ]]
then
#found no duplicate
newpath[$i]=$d
i=$i+1
fi
done
print "${newpath[*]}"
)
}
PATH="$PATH:$HOME/bin:/usr/local/bin/X11:/usr/local/bin:/usr/sbin:."
PATH=$(reduce_path "$PATH")
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-28-2004 05:32 AM
05-28-2004 05:32 AM
Re: setting PATH
PATH=$PATH:/some/more/path
you could do:
PATH=`cat /etc/PATH`:/some/more/path
and have all the normal stuff in PATH be in the file /etc/PATH?
that way, instead of it adding to the old variable each time, it is redefining the variable each time.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-30-2004 12:40 PM
05-30-2004 12:40 PM
Re: setting PATH
#!/usr/bin/sh
export PATH=/usr/bin:/usr/contrib/bin
PATH can actually be a big security risk or it can run commands from the wrong locations. Write your script and add to PATH as needed and you won't have any problems with PATH growing.
NOTE: If you scipt is being sourced, that is, run by the current shell using the . (dot) command, then you'll need to scan $PATH and append as needed. The reason that the dot command is different is that all scripts are run in a subshell and changes made in the subshell are not propagated back to the parent. But when a script is sourced, it is run in the current shell so changes to $PATH will remain.
Another method is to simply drop the requirement for PATH extension by hardcoding the pathname:
someprogram some_parameters
becomes:
/opt/appname/bin/someprogram some_parameters
and leave $PATH alone.
Bill Hassell, sysadmin