From: znx <znxster@gmail.com>
To: gentoo-user@lists.gentoo.org
Subject: Re: [gentoo-user] bash wizardry needed: PATH and MANPATH grow and grow and grow
Date: Tue, 23 May 2006 21:06:32 +0100 [thread overview]
Message-ID: <169ffc030605231306m37b7e90ayda8315a8b84dff44@mail.gmail.com> (raw)
In-Reply-To: <9acccfe50605211556h542921a9kbd79da6a016e2101@mail.gmail.com>
On 21/05/06, Kevin O'Gorman <kogorman@gmail.com> 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
next prev parent reply other threads:[~2006-05-23 20:16 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2006-05-21 22:56 [gentoo-user] bash wizardry needed: PATH and MANPATH grow and grow and grow Kevin O'Gorman
2006-05-23 20:06 ` znx [this message]
2006-05-24 14:58 ` Kevin O'Gorman
2006-05-26 1:27 ` znx
2006-05-27 2:52 ` Kevin O'Gorman
2006-06-03 21:11 ` znx
2006-07-05 19:33 ` Boyd Stephen Smith Jr.
2006-07-07 18:31 ` Kevin O'Gorman
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=169ffc030605231306m37b7e90ayda8315a8b84dff44@mail.gmail.com \
--to=znxster@gmail.com \
--cc=gentoo-user@lists.gentoo.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox