Gentoo Archives: gentoo-user

From: Kevin O'Gorman <kogorman@×××××.com>
To: gentoo-user@l.g.o
Subject: [gentoo-user] bash wizardry needed: PATH and MANPATH grow and grow and grow
Date: Sun, 21 May 2006 23:05:12
Message-Id: 9acccfe50605211556h542921a9kbd79da6a016e2101@mail.gmail.com
1 I have inherited some pretty gnarly dotfiles that I don't really want to
2 fool with too much,
3 but I'm also unhappy with what they do to my environment. They keep adding
4 the
5 same things over and over to some of the variables.
6
7 Does anyone know a nice little idiom for de-duping a colon-list like PATH or
8 MANPATH?
9 It has to retain one copy of each duplicate, preserving the order of *first*
10 appearances.
11 I know how to avoid duplicates when I do the coding myself:
12 case :$PATH: in
13 *:mynewthing:*) ;;
14 *) export PATH=$PATH:mynewthing
15 esac
16
17 I'm just not sure how best to turn the colon-list into something I can
18 iterate over.
19
20 Obviously, I use bash.
21
22 ++ kevin
23
24 --
25 Kevin O'Gorman, PhD

Replies