From: Mark Wooding Date: Mon, 18 Jan 2010 14:45:04 +0000 (+0000) Subject: dot/bash_profile (__mdw_addto) SECURITY: Only set var if it changed. X-Git-Url: https://git.distorted.org.uk/~mdw/profile/commitdiff_plain/85d3810bff9add23ef3bd9e30b02821b3e6b9279 dot/bash_profile (__mdw_addto) SECURITY: Only set var if it changed. If this isn't done, we end up with empty variables where previously they were unset. This is especially bad for PYTHONPATH, which will pick `site.py' out of the current directory. --- diff --git a/dot/bash_profile b/dot/bash_profile index a6015e9..abd3463 100644 --- a/dot/bash_profile +++ b/dot/bash_profile @@ -19,7 +19,7 @@ cd $HOME # --- Add elements to a path string --- __mdw_addto () { - local var=$1 val dir=$2 new="" + local var=$1 val dir=$2 new="" change=nil eval "val=\$$var" shift 2 for i in "$@"; do @@ -27,7 +27,7 @@ __mdw_addto () { [ -d $i ] || continue case "X$val" in X) - val=$i + val=$i change=t continue ;; X$i) @@ -43,13 +43,13 @@ __mdw_addto () { val=${val%:$i} ;; esac - new=$new:$i + new=$new:$i change=t done case $dir in l) val=${new#:}:$val;; r) val=$val$new;; esac - export $var=$val + case $change in t) export $var=$val ;; esac } # --- Set the path variable ---