Skip to content

Instantly share code, notes, and snippets.

@sethdavis512
Created May 7, 2017 18:42
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sethdavis512/b838087af696a764a6f9e4add2fce306 to your computer and use it in GitHub Desktop.
Save sethdavis512/b838087af696a764a6f9e4add2fce306 to your computer and use it in GitHub Desktop.
Remove duplicate paths from $PATH
# 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