From 06491fde932ad154d2fbfcf5013d3025cefc0125 Mon Sep 17 00:00:00 2001 From: Achim Gsell Date: Fri, 1 Jul 2022 16:35:15 +0200 Subject: [PATCH] modulecmd: issue with PMODULES_HOME fixed in sub-cmd purge the env.variable PMODULES_HOME must be preserved. --- Pmodules/modulecmd.bash.in | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/Pmodules/modulecmd.bash.in b/Pmodules/modulecmd.bash.in index 133a8b8..24f7dcb 100644 --- a/Pmodules/modulecmd.bash.in +++ b/Pmodules/modulecmd.bash.in @@ -1895,13 +1895,15 @@ subcommand_purge() { # is a Pmodule module loaded? # if yes, save name in variable 'pmodule' - local pmodule='' + # We also have to save PMODULES_HOME since it will be + # unset while sourcing the shell's init script. IFS=':' local -a lmfiles=($_LMFILES_) unset IFS for f in "${lmfiles[@]}"; do if [[ $f == */${PMODULES_MODULEFILES_DIR}/Pmodules/* ]]; then - pmodule="${f##*/${PMODULES_MODULEFILES_DIR}/}" + local pm_home="${PMODULES_HOME}" + local pmodule="${f##*/${PMODULES_MODULEFILES_DIR}/}" break; fi done @@ -1931,13 +1933,14 @@ subcommand_purge() { echo "${error}" 1>&2 fi - if [[ -n "${pmodule}" ]]; then + if [[ -v pmodule ]]; then # reload a previously loaded Pmodule module # stderr is redirected to /dev/null, otherwise # we may get output like # 'unstable module has been loaded' + PMODULES_HOME="${pm_home}" + export_env PMODULES_HOME subcommand_load "${pmodule}" 2> /dev/null - # export_env PMODULES_HOME fi init_modulepath