From 4242e30ff7a3a18b9c9cca065ad2d9713b71da07 Mon Sep 17 00:00:00 2001 From: Sandro Wenzel Date: Mon, 26 Jan 2026 11:34:17 +0100 Subject: [PATCH] anchorMC: Fix bug in restoring custom env variable This fixes https://its.cern.ch/jira/browse/O2-6621 The `export $var=$b` command, used to restore environment variables was executed in a sub-shell because we piped into the while loop. This is avoiding by not using a pipe. Instead the while loop iterations are taken from `< <()` notation. --- MC/run/ANCHOR/anchorMC.sh | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/MC/run/ANCHOR/anchorMC.sh b/MC/run/ANCHOR/anchorMC.sh index 732cc7505..9425f8dfb 100755 --- a/MC/run/ANCHOR/anchorMC.sh +++ b/MC/run/ANCHOR/anchorMC.sh @@ -275,14 +275,17 @@ if [ "${ALIEN_JDL_O2DPG_ASYNC_RECO_TAG}" ]; then # Restore overwritten O2DPG variables set by modules but changed by user # (in particular custom O2DPG_ROOT and O2DPG_MC_CONFIG_ROOT) + # We must avoid piping into a while loop (otherwise the internal export is executed in sub-shell) printenv > env_after_restore.printenv - comm -12 <(grep '^O2DPG' env_before_stashing.printenv | cut -d= -f1 | sort) \ - <(grep '^O2DPG' env_after_restore.printenv | cut -d= -f1 | sort) | while read -r var; do b=$(grep "^$var=" env_before_stashing.printenv | cut -d= -f2-) a=$(grep "^$var=" env_after_restore.printenv | cut -d= -f2-) [[ "$b" != "$a" ]] && export "$var=$b" && echo "Reapplied: $var to ${b}" - done + done < <( + comm -12 \ + <(grep '^O2DPG' env_before_stashing.printenv | cut -d= -f1 | sort) \ + <(grep '^O2DPG' env_after_restore.printenv | cut -d= -f1 | sort)) + fi #<----- END OF part that should run under a clean alternative software environment if this was given ------