This is the mail archive of the
mailing list for the Cygwin project.
Useful Cygwinism #2: PATH Despacifier/Deduplicateifier
- From: "Gary R. Van Sickle" <g dot r dot vansickle at worldnet dot att dot net>
- To: "Cygwin mailing list" <cygwin at cygwin dot com>
- Date: Sun, 28 Jul 2002 22:51:43 -0500
- Subject: Useful Cygwinism #2: PATH Despacifier/Deduplicateifier
I've been noticing a lot of traffic lately on people having problems with paths
which contain spaces, admonitions to "keep your PATH as short as possible for
performance reasons", etc. So in the spirit of floating everyone's boat, here's
installment #2 of "Useful Cygwinisms".
Your Windows PATH contains paths with spaces in them, causing you all manner of
grief. It also contains the Windows paths to /bin and /usr/local/bin, to make
running Cygwin apps from the 9x/NT command line easier, but these end up getting
needlessly duplicated when you run a bash session, due to the actions of
A little Perl script I like to call "despaceify":
@pathcomps = split(/:/, shift);
$path=qx(cygpath -u \$(cygpath -ws $path));
print join(":", @pathcomps_out);
This script takes a ":"-separated Unixoid PATH, replaces any component paths
containing spaces with their equivalent "8.3" spaceless replacements, and also
removes any duplicates (only the first instance of a particular path will
remain). To make it work its magic, just save the script as "despaceify"
somewhere convenient (for me, ~/bin/despaceify), of course make sure you have
Perl installed, and then add this to your .bash_profile:
# Clean up PATH.
export PATH=$(~/bin/despaceify "$PATH");
And that's it. Every time you start up a bash session, your PATH will be
automatically scrubbed clean!
This addition adds a slightly annoying ~1-2 second delay to bash startup,
probably from the loading of Perl. However, my Herculean efforts to get such
functionality without Perl (i.e. with just shell scripting and cygpath) came to
naught. I'm guessing an equivalent script might be possible in awk, but that's
an exercise (==challenge) for the reader ;-).
Offer void in CA, AK, WA, and where prohibited by law. No bailment created.
Not to be used as a flotation device. Phenylketonurics: Contains phenylalanine.
To be used only for good, never evil. Contains less than 10% fruit juice. May
not be suitable for some viewers. Light fuse and get away.
Gary R. Van Sickle
Unsubscribe info: http://cygwin.com/ml/#unsubscribe-simple
Bug reporting: http://cygwin.com/bugs.html