chiark / gitweb /
dot/bash_profile (__mdw_addto) SECURITY: Only set var if it changed.
authorMark Wooding <mdw@distorted.org.uk>
Mon, 18 Jan 2010 14:45:04 +0000 (14:45 +0000)
committerMark Wooding <mdw@distorted.org.uk>
Mon, 18 Jan 2010 14:45:04 +0000 (14:45 +0000)
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.

dot/bash_profile

index a6015e97167cdfc827c770cdc57d7224e2aa1441..abd34633a63c64800efa9d759c01eba6448b2a3e 100644 (file)
@@ -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 ---