Guard against nonexistent entries in $PATH

This commit is contained in:
Sam Stephenson 2011-08-14 14:16:26 -05:00
parent bd1e56ff37
commit 3efdf6a243

View file

@ -2,6 +2,10 @@
set -e set -e
expand_path() { expand_path() {
if [ ! -d "$1" ]; then
return 1
fi
local cwd="$(pwd)" local cwd="$(pwd)"
cd "$1" cd "$1"
pwd pwd
@ -14,7 +18,7 @@ remove_from_path() {
for path in ${PATH//:/$'\n'}; do for path in ${PATH//:/$'\n'}; do
path="$(expand_path "$path" || true)" path="$(expand_path "$path" || true)"
if [ "$path" != "$path_to_remove" ]; then if [ -n "$path" ] && [ "$path" != "$path_to_remove" ]; then
result="${result}${path}:" result="${result}${path}:"
fi fi
done done