Why: * Remove dupes from PATH How: $PATH is a scalar composed of contents of $path, so it uses typeset -U ("U" as in Unique) to ensure there are no dupes. It preserves the first occurrence in the array, since it would be searched first before others when matching a command in the directories in the PATH anyway.
10 lines
287 B
Text
10 lines
287 B
Text
# Reorders existing entry in PATH to have it at the front
|
|
#
|
|
# move_to_front_of_path "$HOME/.bin"
|
|
#
|
|
move_to_front_of_path() {
|
|
if [[ ":$PATH:" == *":$1:"* ]]; then
|
|
PATH=$(echo $PATH | sed 's#'$1'##g' | sed s/:://g | sed s/:$//g | sed s/^://g)
|
|
PATH="$1${PATH:+":$PATH"}"
|
|
fi
|
|
}
|