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='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 > > 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 -- Kevin O'Gorman, PhD