Search This Blog

Tuesday, September 27, 2011

HowTo: Remove duplicates in Linux PATH

CodeSnippets: Remove duplicates in PATH [awk] [shell] [osx] [mac] [bash] [unix] [linux] [environment] [remove] [variable] [path] [duplicate]

Some apps just add paths to your path every time you run them. In this case, my path was over a screen full of duplicates. When adding to a path, grep is an easy check to see if it's there. But when you call something else, you don't know what you're going to get, and how many times it will put the same thing in there.

This one line script is perfect, just hard to find. Couldn't find the original author, but kudo's.

PATH="$(printf "%s" "${PATH}" | /usr/bin/awk -v RS=: -v ORS=: '!($0 in a) {a[$0]; print}')"

(Change ':' to ';' for Windows.)

No comments:

Post a Comment