Gentoo Archives: gentoo-user

From: znx <znxster@×××××.com>
To: gentoo-user@l.g.o
Subject: Re: [gentoo-user] bash wizardry needed: PATH and MANPATH grow and grow and grow
Date: Tue, 23 May 2006 20:16:29
Message-Id: 169ffc030605231306m37b7e90ayda8315a8b84dff44@mail.gmail.com
In Reply to: [gentoo-user] bash wizardry needed: PATH and MANPATH grow and grow and grow by Kevin O'Gorman
1 On 21/05/06, Kevin O'Gorman <kogorman@×××××.com> wrote:
2 > Does anyone know a nice little idiom for de-duping a colon-list like PATH
3 > or MANPATH?
4
5 Yeah this is something that constantly annoyed me, I forget where I
6 found this (although I moved it to a function), it is not of my
7 creation.
8
9 To ensure no confusion with the below paste, I have additionally
10 placed this in a text file:
11 http://kutzooi.co.uk/cleanpath.sh.txt
12
13 function cleanpath {
14 # Removes duplicates from PATH style variables
15 local variable='PATH'
16 if [ $# -eq 1 ]
17 then
18 variable="$1"
19 fi
20 local var="${1:-${variable}}" oldpath newpath=: entry
21 oldpath="${!var}:"
22 while [ -n "$oldpath" ]; do
23 entry="${oldpath%%:*}"
24 oldpath="${oldpath#*:}"
25 [ "${entry:0:1}" = / ] && [ -n "${newpath##*:$entry:*}" ] && \
26 [ -d "$entry" ] && newpath="$newpath$entry:"
27 done
28 newpath="${newpath#:}"
29 eval "$var"'="${newpath%:}"'
30 }
31
32 cleanpath # defaults to PATH
33 cleanpath MANPATH
34 cleanpath LD_LIBRARY_PATH
35
36 Hope this helps.
37 Mark
38
39 --
40 gentoo-user@g.o mailing list

Replies

Subject Author
Re: [gentoo-user] bash wizardry needed: PATH and MANPATH grow and grow and grow Kevin O'Gorman <kogorman@×××××.com>