changeset 1634:4a82073cc315

8135014: logger.sh needs to handle commands with variable assignment prefixes Reviewed-by: erikj
author ihse
date Thu, 03 Sep 2015 15:01:57 +0200
parents c356ee0434a0
children b8afcf91331d 81140a77ebd8
files common/bin/logger.sh
diffstat 1 files changed, 14 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/common/bin/logger.sh	Thu Sep 03 11:05:49 2015 +0200
+++ b/common/bin/logger.sh	Thu Sep 03 15:01:57 2015 +0200
@@ -41,5 +41,19 @@
 trap "rm -rf \"$RCDIR\"" EXIT
 LOGFILE=$1
 shift
+
+# We need to handle command likes like "VAR1=val1 /usr/bin/cmd VAR2=val2".
+# Do this by shifting away prepended variable assignments, and export them
+# instead.
+is_prefix=true
+for opt; do
+  if [[ "$is_prefix" = true && "$opt" =~ ^.*=.*$ ]]; then
+    export $opt
+    shift
+  else
+    is_prefix=false
+  fi
+done
+
 (exec 3>&1 ; ("$@" 2>&1 1>&3; echo $? > "$RCDIR/rc") | tee -a $LOGFILE 1>&2 ; exec 3>&-) | tee -a $LOGFILE
 exit `cat "$RCDIR/rc"`