diff --git a/Pmodules/bash b/Pmodules/bash index da864f7..c761057 100644 --- a/Pmodules/bash +++ b/Pmodules/bash @@ -16,12 +16,24 @@ module() { local -r modulecmd="${PMODULES_HOME}/bin/modulecmd" local -a args=() - local -a switches=() + local -a modulecmd_opts=() + local -a subcmd_opts=() - while (( $# > 0 ));do + while (( $# > 0 )); do case $1 in -* ) - switches+=( $1 ) + modulecmd_opts+=( $1 ) + shift + ;; + * ) + break + ;; + esac + done + while (( $# > 0 )); do + case $1 in + -* ) + subcmd_opts+=( $1 ) ;; [/~a-zA-Z]* ) args+=( $1 ) @@ -33,11 +45,13 @@ module() { [[ ${#args[@]} == 0 ]] && args+=( 'help' ) [[ ${#args[@]} == 1 ]] && args+=( '--' ) - # we have to eval here, otherwise we cannot do something like + # Loop over all modules to load. + # Note: We have to eval here, otherwise we cannot do something like # $ module load gcc/5.2.0 openmpi/1.8.8 hdf5/1.8.15 local -i i=1 for (( i=1; i < ${#args[@]}; i++ )); do - eval $( "${modulecmd}" bash "${args[0]}" "${switches[@]}" "${args[i]}" ) + eval $( "${modulecmd}" bash "${modulecmd_opts[@]}" "${args[0]}" \ + "${subcmd_opts[@]}" "${args[i]}" ) done } export -f module