Revision 10020
Added by Aaron Marcuse-Kubitza over 11 years ago
lib/sh/util.sh | ||
---|---|---|
664 | 664 |
PATH_rm() # usage: PATH_rm path... # removes components from the PATH |
665 | 665 |
{ |
666 | 666 |
echo_func; echo_vars PATH; : "${PATH?}" |
667 |
PATH=":$PATH:" # add *extra* : to match at beginning and end |
|
668 |
for path in "$@"; do PATH="${PATH//:$path:/:}"; done |
|
669 |
PATH="${PATH#:}" # remove any remaining extra leading : |
|
670 |
PATH="${PATH%:}" # remove any remaining extra trailing : |
|
667 |
log+ 2 |
|
668 |
split : "$PATH" |
|
669 |
local new_paths=() |
|
670 |
for path in "${parts[@]}"; do |
|
671 |
if ! contains "$path" "$@"; then new_paths+=("$path"); fi |
|
672 |
done |
|
673 |
PATH="$(delim=: join "${new_paths[@]}")" || return |
|
674 |
log+ -2 |
|
671 | 675 |
echo_vars PATH |
672 | 676 |
} |
673 | 677 |
|
Also available in: Unified diff
bugfix: lib/sh/util.sh: PATH_rm(): also need to remove adjacent occurrences of the same path (or occurrences which become adjacent when other paths are removed), which :...: matching wasn't doing because the trailing : is consumed, preventing it from being matched at the beginning of the next path. since unlike filesystem paths with /, it is not necessary for a match to span multiple :-separated sections, we can just use new split() to split apart the PATH into an array of paths, filter each path, and join() them back together.