Answers for "Clean Repetitive PATHs"

0

Clean Repetitive PATHs

# Here's a shell snippet that removes duplicates from $PATH. 
# It goes through the entries one by one, and copies those that haven't been seen yet.
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
Posted by: Guest on May-30-2021

Code answers related to "Shell/Bash"

Browse Popular Code Answers by Language