Files
modules/init/bash.in

94 lines
3.4 KiB
Plaintext

# only redirect module from stderr to stdout in interactive mode
# to avoid breaking non interactive session (scp, sftp, etc)
if [[ $- =~ i ]]; then
_moduleraw() { eval `@TCLSH@ @libexecdir@/modulecmd.tcl bash $*`; }
module() { _moduleraw $* 2>&1 ; }
# export functions to get them defined in sub-shells
export -f _moduleraw
export -f module
else
module() { eval `@TCLSH@ @libexecdir@/modulecmd.tcl bash $*`; }
export -f module
fi
@setswitchml@# define function to switch between C and Tcl versions of Modules
@setswitchml@switchml() {
@setswitchml@ # determine currently used module version
@setswitchml@ typeset currel=`module --version 2>&1 | grep -E '^(Modules|VERSION=)'`
@setswitchml@ if [[ "$currel" =~ 'Tcl' ]]; then
@setswitchml@ typeset mlver='Tcl'
@setswitchml@ typeset curpath='@swmlbindir@'
@setswitchml@ typeset curmanpath='@swmlmandir@'
@setswitchml@ elif [[ "$currel" =~ 'VERSION' ]]; then
@setswitchml@ typeset mlver='C'
@setswitchml@ typeset curpath='@cverbindir@'
@setswitchml@ typeset curmanpath='@cvermandir@'
@setswitchml@ fi
@setswitchml@
@setswitchml@ # remove specific paths set by current module version
@setswitchml@ if [ -n "$PATH" -a "${curpath:-}" != '' ]; then
@setswitchml@ PATH=${PATH/:$curpath/}
@setswitchml@ PATH=${PATH/$curpath:/}
@setswitchml@ fi
@setswitchml@ if [ -n "$MANPATH" -a "${curmanpath:-}" != '' ]; then
@setswitchml@ MANPATH=${MANPATH/:$curmanpath/}
@setswitchml@ MANPATH=${MANPATH/$curmanpath:/}
@setswitchml@ fi
@setswitchml@
@setswitchml@ # switch module version
@setswitchml@ if [ "$mlver" = 'Tcl' ]; then
@setswitchml@ if [ -d @cverinitdir@ ]; then
@setswitchml@ echo 'Switching to Modules C version'
@setswitchml@ source @cverinitdir@/bash
@setswitchml@ else
@setswitchml@ echo 'Cannot find Modules C version'
@setswitchml@ return 1
@setswitchml@ fi
@setswitchml@ else
@setswitchml@ echo 'Switching to Modules Tcl version'
@setswitchml@ source @initdir@/bash
@setswitchml@ fi
@setswitchml@}
@setswitchml@export -f switchml
@setswitchml@
# setup ENV variables to get module defined in sub-shells (works for 'sh'
# and 'ksh' in interactive mode and 'sh' (zsh-compat), 'bash' and 'ksh'
# (zsh-compat) in non-interactive mode.
ENV=@initdir@/profile.sh; export ENV
BASH_ENV=@initdir@/bash; export BASH_ENV
# enable completion only in interactive mode
if [ ${BASH_VERSINFO:-0} -ge 3 ] && [[ $- =~ i ]] &&
[ -r @initdir@/bash_completion ]; then
source @initdir@/bash_completion
fi
MODULESHOME=@prefix@; export MODULESHOME
@setbinpath@if [[ ! ":$PATH:" =~ ':@bindir@:' ]]; then
@setbinpath@ PATH=@bindir@${PATH:+:}$PATH; export PATH
@setbinpath@fi
@setbinpath@
@setmanpath@manpath=`manpath 2>/dev/null`
@setmanpath@if [[ ! ":$manpath:" =~ ':@mandir@:' ]]; then
@setmanpath@ MANPATH=@mandir@${manpath:+:}$manpath; export MANPATH
@setmanpath@fi
@setmanpath@
if [ "${MODULEPATH:-}" = '' ]; then
if [ -r @initdir@/.modulespath ]; then
MODULEPATH=`sed -n 's/[ #].*$//; /./H; $ { x; s/^\n//; s/\n/:/g; p; }' \
@initdir@/.modulespath`; export MODULEPATH
else
MODULEPATH=; export MODULEPATH
fi
fi
if [ "${LOADEDMODULES:-}" = '' ]; then
LOADEDMODULES=; export LOADEDMODULES
fi
# load modulerc only if module environment is empty
if [ -r @initdir@/modulerc -a "$MODULEPATH" = '' -a "$LOADEDMODULES" = '' ]; then
source @initdir@/modulerc
fi