| Category: | Utility Code |
| Author/Contact Info | aepage@users.sourceforge.net |
| Description: | Perl -e command for scrubbing duplicate directories out of your PATH variable in bash, sh and ksh. Place after the last modification of the PATH. Order of the entries is preserved. |
export PATH=`perl -e 'print join ":", (grep $h{$_}++ < 1, split /:/,$E
+NV{PATH}), "\n" ;'`
Nuts and BoltsUnix path specifications are delimited by colons(:). The line breaks the existing entry into a list of separate directories1. It then iterates over that list, at each directory it references an entry in the %h hash and increments it2. If the entry previously did not exist, the entry will be undef, the entry will be added to a new list. If the entry already exists, it will be skipped. The resulting list is then passed to 'join' where the entries will be joined into a string, with a ":" between each entry3. The result is printed4. This expression is evaluated by the -e option of perl5 and put back into the PATH variable with the ``6.
|
|
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: PATH environmental variable scrubber
by Yendor (Pilgrim) on Oct 09, 2003 at 21:15 UTC | |
|
•Re: PATH environmental variable scrubber
by merlyn (Sage) on Oct 09, 2003 at 22:16 UTC | |
by runrig (Abbot) on Oct 09, 2003 at 22:22 UTC | |
by Yendor (Pilgrim) on Oct 12, 2003 at 04:18 UTC |