While on the PATH manipulation subject, I find the following function
handy when using ksh.  It eliminates duplicates in a PATH style string.
This is useful when one has a lot of things like:

   export PATH="$PATH;/some/new/stuff"

These tend to accumulate a lot of duplicate entries which can be eliminated
using this function by:

   RemoveDups "$PATH"
   export PATH="$_RemoveDups"


Sorry about the formatting ... the cut-n-paste clobbers the tabs characters.

==================================================
# RemoveDups( PATH )
#
# This function will remove all duplicate entries in the path
# specification passed and return the result in _RemoveDups.
#
# Parameters: PATH The path specification
#
# Returns: _RemoveDups Updated PATH (with duplicates removed)
#

function RemoveDups

{
 typeset _IFS=$IFS  # Save this
 typeset p
 typeset p1
 typeset _PATH="$1"

 _RemoveDups=""   # Return value

 for p in $_PATH
 do
  # There has got to be an easier way to test for duplicates,
     # but lacking a "unique" or a "test" that can do string
  # searches I'm stuck for the moment with this:

  for p1 in $_RemoveDups
  do
   if [ "$p" = "$p1" ]
   then
    p=
    break
   fi
  done

  if [ "$p" != "" ]
  then
   if [ -d $p ]
   then
    _RemoveDups=${_RemoveDups#:}:$p
   fi
  fi
 done

 IFS=$_IFS

} # RemoveDups()




Mike McNally wrote:

> What I've always done is keep a little script around that
> constructs the path from a more easily edited list. When
> you're doing a lot of development against some sort of
> application framework(s), your path tends to get kinda
> nasty.
>
> So you put a script in your home directory (or your
> $HOME/bin.sh or wherever you like) called something like
> GETPATH. It should look something like this:
>
> #!/bin/sh
>
> pathdirs='
>   $HOME/bin.sh
>   $HOME/bin
>   /usr/local/bin
>   /usr/bin
>   /usr/sbin
>   /bin
>   /sbin
>   /what/ever/you/want
> '
>
> set $pd
> PATHSTR=$1
> shift
> for pd in "$@"; do
>   PATHSTR="$PATHSTR:$pd"
> done
>
> echo $PATHSTR
> #end
>
> You can then run that script from a little shell function or alias
> or whatever. I just find it a lot easier to edit the vertical list
> of directories than a big wad of colon-separated pathnames.
>
> -----Original Message-----
> From: Jake McHenry
> To: redhat
> Sent: 5/7/00 9:10 AM
> Subject: Re: How do I edit my PATH?
>
> Your path environment is set in your *.profile located in each users
> directory. just edit this file and somewhere you should see PATH=
> just add to this whatever you want
>
> jake
>
> On Sun, 7 May 2000, John P. Verel wrote:
>
> > I'm running Red Hat 6.2  I want to edit my path environment and am
> > unclear where to go to do it, unable to find appropriate documentation
> > on this.  Can someone please advise?  Thank you.
> >
> > John
> >
> >
> > --
> > To unsubscribe: mail [EMAIL PROTECTED] with "unsubscribe"
> > as the Subject.
> >
> >
>
> Jake McHenry
> [EMAIL PROTECTED]
>
> --
> To unsubscribe: mail [EMAIL PROTECTED] with "unsubscribe"
> as the Subject.
>
> --
> To unsubscribe: mail [EMAIL PROTECTED] with "unsubscribe"
> as the Subject.


-- 
To unsubscribe: mail [EMAIL PROTECTED] with "unsubscribe"
as the Subject.

Reply via email to