Created
May 7, 2017 18:42
-
-
Save sethdavis512/b838087af696a764a6f9e4add2fce306 to your computer and use it in GitHub Desktop.
Remove duplicate paths from $PATH
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Taken from https://unix.stackexchange.com/questions/40749/remove-duplicate-path-entries-with-awk-command | |
if [ -n "$PATH" ]; then | |
old_PATH=$PATH:; PATH= | |
while [ -n "$old_PATH" ]; do | |
x=${old_PATH%%:*} # the first remaining entry | |
case $PATH: in | |
*:"$x":*) ;; # already there | |
*) PATH=$PATH:$x;; # not there yet | |
esac | |
old_PATH=${old_PATH#*:} | |
done | |
PATH=${PATH#:} | |
unset old_PATH x | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment