Pmodules/bash

- bug-fix in passing options to modulecmd (issue #8)
This commit is contained in:
2017-02-07 17:54:51 +01:00
parent ef2df8ea3d
commit d7dbccd0e4
+19 -5
View File
@@ -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