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 1FidIq-0001Ft-Sa for garchives@archives.gentoo.org; Tue, 23 May 2006 20:16: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 k4NKF81N028801; Tue, 23 May 2006 20:15:08 GMT Received: from wx-out-0102.google.com (wx-out-0102.google.com [66.249.82.201]) by robin.gentoo.org (8.13.6/8.13.6) with ESMTP id k4NK6Yuu020239 for ; Tue, 23 May 2006 20:06:34 GMT Received: by wx-out-0102.google.com with SMTP id s10so736553wxc for ; Tue, 23 May 2006 13:06:33 -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:content-transfer-encoding:content-disposition:references; b=kxnO6L4/+Zr/DkW3/8ES7ZbiMkGisltMXsU7TMXDeLljJJYcxUWNJL9gM5phZAn+cYe/b7mWkh+cDJNUXNXKO9g7OTFYsYL7mbtojMNwdsxsEeCVXUvWtPMwShny8pxT6/WUOENyZ0rAxX3PmfSeRWWl/0g6mHGlTKpsz7YFZUA= Received: by 10.70.65.14 with SMTP id n14mr6810613wxa; Tue, 23 May 2006 13:06:33 -0700 (PDT) Received: by 10.70.40.14 with HTTP; Tue, 23 May 2006 13:06:32 -0700 (PDT) Message-ID: <169ffc030605231306m37b7e90ayda8315a8b84dff44@mail.gmail.com> Date: Tue, 23 May 2006 21:06:32 +0100 From: znx To: gentoo-user@lists.gentoo.org Subject: Re: [gentoo-user] bash wizardry needed: PATH and MANPATH grow and grow and grow In-Reply-To: <9acccfe50605211556h542921a9kbd79da6a016e2101@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: text/plain; charset=ISO-8859-1; format=flowed Content-Disposition: inline References: <9acccfe50605211556h542921a9kbd79da6a016e2101@mail.gmail.com> Content-Transfer-Encoding: 8bit X-MIME-Autoconverted: from quoted-printable to 8bit by robin.gentoo.org id k4NK6Yuu020239 X-Archives-Salt: ecb0d518-c594-47bd-8e77-ec7dc5efcabf X-Archives-Hash: 91e5409c7882060b09c1509ebfff2582 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='PATH' if [ $# -eq 1 ] then variable="$1" fi local var="${1:-${variable}}" oldpath newpath=: entry oldpath="${!var}:" while [ -n "$oldpath" ]; do entry="${oldpath%%:*}" oldpath="${oldpath#*:}" [ "${entry:0:1}" = / ] && [ -n "${newpath##*:$entry:*}" ] && \ [ -d "$entry" ] && newpath="$newpath$entry:" done newpath="${newpath#:}" eval "$var"'="${newpath%:}"' } cleanpath # defaults to PATH cleanpath MANPATH cleanpath LD_LIBRARY_PATH Hope this helps. Mark -- gentoo-user@gentoo.org mailing list