Skip to content

Commit f0bc26c

Browse files
committed
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.
1 parent 1da166a commit f0bc26c

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

MC/run/ANCHOR/anchorMC.sh

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -275,14 +275,17 @@ if [ "${ALIEN_JDL_O2DPG_ASYNC_RECO_TAG}" ]; then
275275

276276
# Restore overwritten O2DPG variables set by modules but changed by user
277277
# (in particular custom O2DPG_ROOT and O2DPG_MC_CONFIG_ROOT)
278+
# We must avoid piping into a while loop (otherwise the internal export is executed in sub-shell)
278279
printenv > env_after_restore.printenv
279-
comm -12 <(grep '^O2DPG' env_before_stashing.printenv | cut -d= -f1 | sort) \
280-
<(grep '^O2DPG' env_after_restore.printenv | cut -d= -f1 | sort) |
281280
while read -r var; do
282281
b=$(grep "^$var=" env_before_stashing.printenv | cut -d= -f2-)
283282
a=$(grep "^$var=" env_after_restore.printenv | cut -d= -f2-)
284283
[[ "$b" != "$a" ]] && export "$var=$b" && echo "Reapplied: $var to ${b}"
285-
done
284+
done < <(
285+
comm -12 \
286+
<(grep '^O2DPG' env_before_stashing.printenv | cut -d= -f1 | sort) \
287+
<(grep '^O2DPG' env_after_restore.printenv | cut -d= -f1 | sort)
288+
286289
fi
287290
#<----- END OF part that should run under a clean alternative software environment if this was given ------
288291

0 commit comments

Comments
 (0)