From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from lists.gentoo.org ([140.105.134.102] helo=robin.gentoo.org) by nuthatch.gentoo.org with esmtp (Exim 4.60) (envelope-from ) id 1Fiv0G-0001j2-Oo for garchives@archives.gentoo.org; Wed, 24 May 2006 15:10:29 +0000 Received: from robin.gentoo.org (localhost [127.0.0.1]) by robin.gentoo.org (8.13.6/8.13.6) with SMTP id k4OF9q5v020693; Wed, 24 May 2006 15:09:52 GMT Received: from py-out-1112.google.com (py-out-1112.google.com [64.233.166.180]) by robin.gentoo.org (8.13.6/8.13.6) with ESMTP id k4OEwmRJ022522 for ; Wed, 24 May 2006 14:58:49 GMT Received: by py-out-1112.google.com with SMTP id z59so2211865pyg for ; Wed, 24 May 2006 07:58:48 -0700 (PDT) DomainKey-Signature: a=rsa-sha1; q=dns; c=nofws; s=beta; d=gmail.com; h=received:message-id:date:from:to:subject:in-reply-to:mime-version:content-type:references; b=b91zKEVBsy0atQ98IE8CM6pyrQxdNV2sFDKwbLBosemIjrHsAxA+cyX79NPm/TjsT46ajZHfzBBBL12xUEO+olGH9l2J4JKChVyWc4LqlSVuwvLK4FVErACg77CeNVID0t4XjsntmA0qcJyLr2yxIZvRun1ycvjqPrCcCd7NeyQ= Received: by 10.35.8.1 with SMTP id l1mr2263814pyi; Wed, 24 May 2006 07:58:48 -0700 (PDT) Received: by 10.35.105.8 with HTTP; Wed, 24 May 2006 07:58:48 -0700 (PDT) Message-ID: <9acccfe50605240758n51991430hc3a15305f0f74133@mail.gmail.com> Date: Wed, 24 May 2006 07:58:48 -0700 From: "Kevin O'Gorman" To: gentoo-user@lists.gentoo.org Subject: Re: [gentoo-user] bash wizardry needed: PATH and MANPATH grow and grow and grow In-Reply-To: <169ffc030605231306m37b7e90ayda8315a8b84dff44@mail.gmail.com> Precedence: bulk List-Post: List-Help: List-Unsubscribe: List-Subscribe: List-Id: Gentoo Linux mail X-BeenThere: gentoo-user@gentoo.org Reply-to: gentoo-user@lists.gentoo.org MIME-Version: 1.0 Content-Type: multipart/alternative; boundary="----=_Part_11513_10608289.1148482728309" References: <9acccfe50605211556h542921a9kbd79da6a016e2101@mail.gmail.com> <169ffc030605231306m37b7e90ayda8315a8b84dff44@mail.gmail.com> X-Archives-Salt: cf84d89d-0efa-4c4b-b170-bd7c8c3ce0a7 X-Archives-Hash: 61928f37a2feb17a795c124cbbf806af ------=_Part_11513_10608289.1148482728309 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: quoted-printable Content-Disposition: inline On 5/23/06, znx wrote: > > On 21/05/06, Kevin O'Gorman wrote: > > Does anyone know a nice little idiom for de-duping a colon-list like > PATH > > or MANPATH? > > Yeah this is something that constantly annoyed me, I forget where I > found this (although I moved it to a function), it is not of my > creation. > > To ensure no confusion with the below paste, I have additionally > placed this in a text file: > http://kutzooi.co.uk/cleanpath.sh.txt > > function cleanpath { > # Removes duplicates from PATH style variables > local variable=3D'PATH' > if [ $# -eq 1 ] > then > variable=3D"$1" > fi > local var=3D"${1:-${variable}}" oldpath newpath=3D: entry > oldpath=3D"${!var}:" > while [ -n "$oldpath" ]; do > entry=3D"${oldpath%%:*}" > oldpath=3D"${oldpath#*:}" > [ "${entry:0:1}" =3D / ] && [ -n "${newpath##*:$entry:*}"= ] > && \ > [ -d "$entry" ] && newpath=3D"$newpath$entry:" > done > newpath=3D"${newpath#:}" > eval "$var"'=3D"${newpath%:}"' > } > > cleanpath # defaults to PATH > cleanpath MANPATH > cleanpath LD_LIBRARY_PATH > > Hope this helps. > Mark > > -- > gentoo-user@gentoo.org mailing list > > This _does_ help. It's mysterious enough that I tested it, and it seems to work except that it removes "." from any path. This is not quite what I want. ++ kevin --=20 Kevin O'Gorman, PhD ------=_Part_11513_10608289.1148482728309 Content-Type: text/html; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable Content-Disposition: inline On 5/23/06, znx <znxster@gmail.com> wrote:
On 21/05/06, Kevin O'Gorman <kogor= man@gmail.com> wrote:
>  Does anyone know a nice lit= tle idiom for de-duping a colon-list like PATH
> or MANPATH?

Y= eah this is something that constantly annoyed me, I forget where I
found this (although I moved it to a function), it is not of my
crea= tion.

To ensure no confusion with the below paste, I have additional= ly
placed this in a text file:
http://kutzooi.co.uk/cleanpath.sh.txt

function cleanpath {
&n= bsp;            = ;   # Removes duplicates from PATH style variables
    &nb= sp;   local variable=3D'PATH'
    &nb= sp;   if [ $# -eq 1 ]
      = ;  then
         =        variable=3D"$1"
&nbs= p;       fi
    &= nbsp;   local var=3D"${1:-${variable}}" oldpath ne= wpath=3D: entry
        oldpath=3D"${!var}= :"
        while [ -n "= ;$oldpath" ]; do
        &n= bsp;       entry=3D"${oldpath%%:*}&= quot;
           =      oldpath=3D"${oldpath#*:}"
 =             &nb= sp;  [ "${entry:0:1}" =3D / ] && [ -n "${newpath##*:$entry:= *}" ] && \
          = ;            &n= bsp; [ -d "$entry" ] && newpath=3D"$newpath$entry:"        done
   =      newpath=3D"${newpath#:}"
 &= nbsp;      eval "$var"'=3D"${n= ewpath%:}"'
}

cleanpath      &= nbsp;           &nbs= p;            &= nbsp;       # defaults to PATH
cleanpath MANPATH
cleanpath LD_LIBRARY_PATH
Hope this helps.
Mark

--
gentoo-user@gentoo.org mailing list

This _does_ help.  It's mysterious enough that I tested it, and it see= ms to work
except that it removes "." from any path.  This is not quite= what I want.

++ kevin


--
Kevin O'Gorman, PhD
------=_Part_11513_10608289.1148482728309-- -- gentoo-user@gentoo.org mailing list