dot/profile: Add a new function to export a variable only if it's defined.
authorMark Wooding <mdw@distorted.org.uk>
Sat, 30 May 2020 12:10:32 +0000 (13:10 +0100)
committerMark Wooding <mdw@distorted.org.uk>
Sat, 30 May 2020 12:21:33 +0000 (13:21 +0100)
This is useful for pathish variables: if they're exported then they're
set to empty, which implies the current directory.

dot/profile

index 6730a25..2d597bf 100644 (file)
@@ -57,6 +57,17 @@ __mdw_setconf () {
   fi
 }
 
+## __mdw_export_if_defined VAR ...
+##
+## If VARs are defined, then export them.
+__mdw_export_if_defined () {
+  local var t
+  for var in "$@"; do
+    eval t=\${$var+t}
+    case $t in t) export $var ;; esac
+  done
+}
+
 ###--------------------------------------------------------------------------
 ### Other preliminaries.