<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic setting PATH in Operating System - HP-UX</title>
    <link>https://community.hpe.com/t5/operating-system-hp-ux/setting-path/m-p/3289140#M181779</link>
    <description>I have a script that adds to a path, but it adds it everytime that I run the script. How do I make it so that the script checks the path first and if the directory that I want to add is already in the path I don't want it to set anything.</description>
    <pubDate>Thu, 27 May 2004 13:08:36 GMT</pubDate>
    <dc:creator>Angela Swyers_1</dc:creator>
    <dc:date>2004-05-27T13:08:36Z</dc:date>
    <item>
      <title>setting PATH</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/setting-path/m-p/3289140#M181779</link>
      <description>I have a script that adds to a path, but it adds it everytime that I run the script. How do I make it so that the script checks the path first and if the directory that I want to add is already in the path I don't want it to set anything.</description>
      <pubDate>Thu, 27 May 2004 13:08:36 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/setting-path/m-p/3289140#M181779</guid>
      <dc:creator>Angela Swyers_1</dc:creator>
      <dc:date>2004-05-27T13:08:36Z</dc:date>
    </item>
    <item>
      <title>Re: setting PATH</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/setting-path/m-p/3289141#M181780</link>
      <description>Hi,&lt;BR /&gt;&lt;BR /&gt;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.&lt;BR /&gt;&lt;BR /&gt;JP&lt;BR /&gt;</description>
      <pubDate>Thu, 27 May 2004 13:12:52 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/setting-path/m-p/3289141#M181780</guid>
      <dc:creator>John Poff</dc:creator>
      <dc:date>2004-05-27T13:12:52Z</dc:date>
    </item>
    <item>
      <title>Re: setting PATH</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/setting-path/m-p/3289142#M181781</link>
      <description>Hi,&lt;BR /&gt;&lt;BR /&gt;You can do something like this:&lt;BR /&gt;#!/usr/bin/sh&lt;BR /&gt;pchk(){&lt;BR /&gt;if echo $1|sed 's/:/\&lt;BR /&gt;/g'|sed 's/$/:/&lt;BR /&gt;s/^/:/' |grep :${2}: 1&amp;gt;/dev/null ; then&lt;BR /&gt;  return 1&lt;BR /&gt;else&lt;BR /&gt;  return 0&lt;BR /&gt;fi&lt;BR /&gt;}&lt;BR /&gt;#-------------------------------------------------------------&lt;BR /&gt;export ORACLE_HOME=/home/oracle/orahome&lt;BR /&gt;#-------------------------------------------------------------&lt;BR /&gt;if [ -z "$SHLIB_PATH" ]; then&lt;BR /&gt;  export SHLIB_PATH=$ORACLE_HOME/lib&lt;BR /&gt;else&lt;BR /&gt;  if pchk $SHLIB_PATH $ORACLE_HOME/lib ;then&lt;BR /&gt;    export SHLIB_PATH=$ORACLE_HOME/lib:$SHLIB_PATH&lt;BR /&gt;  fi&lt;BR /&gt;fi&lt;BR /&gt;&lt;BR /&gt;HTH</description>
      <pubDate>Thu, 27 May 2004 13:14:49 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/setting-path/m-p/3289142#M181781</guid>
      <dc:creator>Victor Fridyev</dc:creator>
      <dc:date>2004-05-27T13:14:49Z</dc:date>
    </item>
    <item>
      <title>Re: setting PATH</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/setting-path/m-p/3289143#M181782</link>
      <description>This script is run over and over and it keeps adding the directory over and over to the path. My user said that it's causing problems. It complained about the PATH being too large.</description>
      <pubDate>Thu, 27 May 2004 13:15:01 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/setting-path/m-p/3289143#M181782</guid>
      <dc:creator>Angela Swyers_1</dc:creator>
      <dc:date>2004-05-27T13:15:01Z</dc:date>
    </item>
    <item>
      <title>Re: setting PATH</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/setting-path/m-p/3289144#M181783</link>
      <description>Your PATH should get set once by the script when it starts running, and should be discarded when the script exits.  I don't think you can pass the PATH back to the parent process.  Does your script set the PATH inside of a loop?  That could cause a problem.  Even so, if you explicity set the path...&lt;BR /&gt;&lt;BR /&gt;PATH=/usr/bin:/somepath&lt;BR /&gt;&lt;BR /&gt;instead of adding to it...&lt;BR /&gt;&lt;BR /&gt;PATH=${PATH}:/somepath&lt;BR /&gt;&lt;BR /&gt;you won't have to worry about it.&lt;BR /&gt;&lt;BR /&gt;JP&lt;BR /&gt;</description>
      <pubDate>Thu, 27 May 2004 13:19:06 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/setting-path/m-p/3289144#M181783</guid>
      <dc:creator>John Poff</dc:creator>
      <dc:date>2004-05-27T13:19:06Z</dc:date>
    </item>
    <item>
      <title>Re: setting PATH</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/setting-path/m-p/3289145#M181784</link>
      <description>Like John mentionned already, your PATH should be discarded as soon as the script is over.. but a quick way to check for your PATH would be :&lt;BR /&gt;&lt;BR /&gt;NEWPATH=path&lt;BR /&gt;&lt;BR /&gt;echo $PATH|grep $NEWPATH &amp;gt;/dev/null&lt;BR /&gt;if [ $? != 0 ]&lt;BR /&gt;then&lt;BR /&gt;  export PATH=${PATH}:${NEWPATH}&lt;BR /&gt;else&lt;BR /&gt;  echo "$NEWPATH is already in PATH"&lt;BR /&gt;fi&lt;BR /&gt;&lt;BR /&gt;</description>
      <pubDate>Thu, 27 May 2004 13:22:52 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/setting-path/m-p/3289145#M181784</guid>
      <dc:creator>Marco Santerre</dc:creator>
      <dc:date>2004-05-27T13:22:52Z</dc:date>
    </item>
    <item>
      <title>Re: setting PATH</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/setting-path/m-p/3289146#M181785</link>
      <description>$(echo $PATH|tr ":" "\n"|grep "xxx") || export PATH=$PATH:/xxx&lt;BR /&gt;&lt;BR /&gt;Anil</description>
      <pubDate>Thu, 27 May 2004 13:32:46 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/setting-path/m-p/3289146#M181785</guid>
      <dc:creator>RAC_1</dc:creator>
      <dc:date>2004-05-27T13:32:46Z</dc:date>
    </item>
    <item>
      <title>Re: setting PATH</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/setting-path/m-p/3289147#M181786</link>
      <description>L.S.&lt;BR /&gt;&lt;BR /&gt;As stated by another JP in this thread:&lt;BR /&gt;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.&lt;BR /&gt;&lt;BR /&gt;So one of the first commands of your script should be something like &lt;BR /&gt;PATH=/my/additional/path:$PATH or&lt;BR /&gt;PATH=$PATH:/my/additional/path.&lt;BR /&gt;&lt;BR /&gt;Keep it simple!&lt;BR /&gt;&lt;BR /&gt;JP&lt;BR /&gt;&lt;BR /&gt;P.S. For completeness: only if you source a script (i.e. '. myscript') the variables are set in the current shell.</description>
      <pubDate>Fri, 28 May 2004 01:30:02 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/setting-path/m-p/3289147#M181786</guid>
      <dc:creator>Jeroen Peereboom</dc:creator>
      <dc:date>2004-05-28T01:30:02Z</dc:date>
    </item>
    <item>
      <title>Re: setting PATH</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/setting-path/m-p/3289148#M181787</link>
      <description>Here is a general method for removing duplicate&lt;BR /&gt;entries from a path.  I have it in my .profile&lt;BR /&gt;so it can add directories that are not already&lt;BR /&gt;in the path but refrain from creating duplicates&lt;BR /&gt;for directories that were already set by&lt;BR /&gt;/etc/profile.&lt;BR /&gt;&lt;BR /&gt;function reduce_path&lt;BR /&gt;{&lt;BR /&gt;    #remove duplicate directories from a path&lt;BR /&gt;    typeset -i i j&lt;BR /&gt;    i=0&lt;BR /&gt;    (&lt;BR /&gt;        IFS=: #break up path at colon delimiters&lt;BR /&gt;        for d in $1&lt;BR /&gt;        do&lt;BR /&gt;            j=0&lt;BR /&gt;            while [[ $j -lt $i ]]&lt;BR /&gt;            do&lt;BR /&gt;                if [[ $d = ${newpath[$j]} ]]&lt;BR /&gt;                then&lt;BR /&gt;                    #found a duplicate&lt;BR /&gt;                    break;&lt;BR /&gt;                fi&lt;BR /&gt;                j=$j+1&lt;BR /&gt;            done&lt;BR /&gt;            if [[ $j = $i ]]&lt;BR /&gt;            then&lt;BR /&gt;                #found no duplicate&lt;BR /&gt;                newpath[$i]=$d&lt;BR /&gt;                i=$i+1&lt;BR /&gt;            fi&lt;BR /&gt;        done&lt;BR /&gt;        print "${newpath[*]}"&lt;BR /&gt;    )&lt;BR /&gt;}&lt;BR /&gt;&lt;BR /&gt;PATH="$PATH:$HOME/bin:/usr/local/bin/X11:/usr/local/bin:/usr/sbin:."&lt;BR /&gt;PATH=$(reduce_path "$PATH")&lt;BR /&gt;</description>
      <pubDate>Fri, 28 May 2004 12:20:52 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/setting-path/m-p/3289148#M181787</guid>
      <dc:creator>Mike Stroyan</dc:creator>
      <dc:date>2004-05-28T12:20:52Z</dc:date>
    </item>
    <item>
      <title>Re: setting PATH</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/setting-path/m-p/3289149#M181788</link>
      <description>in your script, instead of doing just a:&lt;BR /&gt;&lt;BR /&gt;PATH=$PATH:/some/more/path&lt;BR /&gt;&lt;BR /&gt;you could do:&lt;BR /&gt;&lt;BR /&gt;PATH=`cat /etc/PATH`:/some/more/path&lt;BR /&gt;&lt;BR /&gt;and have all the normal stuff in PATH be in the file /etc/PATH?&lt;BR /&gt;&lt;BR /&gt;that way, instead of it adding to the old variable each time, it is redefining the variable each time.</description>
      <pubDate>Fri, 28 May 2004 12:32:32 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/setting-path/m-p/3289149#M181788</guid>
      <dc:creator>Ken Penland_1</dc:creator>
      <dc:date>2004-05-28T12:32:32Z</dc:date>
    </item>
    <item>
      <title>Re: setting PATH</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/setting-path/m-p/3289150#M181789</link>
      <description>Another point of view is to NEVER inherit $PATH in your script. Instead, forget completely about what PATH contains and define it at the beginning of the script:&lt;BR /&gt; &lt;BR /&gt;#!/usr/bin/sh&lt;BR /&gt;export PATH=/usr/bin:/usr/contrib/bin&lt;BR /&gt; &lt;BR /&gt;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.&lt;BR /&gt; &lt;BR /&gt;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.&lt;BR /&gt; &lt;BR /&gt;Another method is to simply drop the requirement for PATH extension by hardcoding the pathname:&lt;BR /&gt; &lt;BR /&gt;someprogram some_parameters&lt;BR /&gt; &lt;BR /&gt;becomes:&lt;BR /&gt; &lt;BR /&gt;/opt/appname/bin/someprogram some_parameters&lt;BR /&gt; &lt;BR /&gt;and leave $PATH alone.</description>
      <pubDate>Sun, 30 May 2004 19:40:47 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/setting-path/m-p/3289150#M181789</guid>
      <dc:creator>Bill Hassell</dc:creator>
      <dc:date>2004-05-30T19:40:47Z</dc:date>
    </item>
  </channel>
</rss>

