diff options
author | Phil Carns <carns@mcs.anl.gov> | 2019-02-13 20:52:18 -0500 |
---|---|---|
committer | Peter Scheibel <scheibel1@llnl.gov> | 2019-02-13 19:52:18 -0600 |
commit | 6971f8ae32c7baf6aedae3de6acee8996040e847 (patch) | |
tree | cde599f36fd970f4118a7d1095107f79d266c177 /share | |
parent | 8ca384875efffbcee1881db9fdef4399e74add50 (diff) | |
download | spack-6971f8ae32c7baf6aedae3de6acee8996040e847.tar.gz spack-6971f8ae32c7baf6aedae3de6acee8996040e847.tar.bz2 spack-6971f8ae32c7baf6aedae3de6acee8996040e847.tar.xz spack-6971f8ae32c7baf6aedae3de6acee8996040e847.zip |
make SPACK_SHELL detection more robust (#9712)
Spack shell detection in setup-env.sh was originally based on
examining the executable name of $$ (from "ps"). In some cases this
does not actually give the name of the shell used, for example when
setup-env.sh was invoked from a script using "#!". To make shell
detection more robust, this adds a preliminary check for shell
variables which indicate that the shell is bash or zsh; the
executable name of $$ is retained as a fallback if those variables
are not defined.
Diffstat (limited to 'share')
-rwxr-xr-x | share/spack/setup-env.sh | 13 |
1 files changed, 12 insertions, 1 deletions
diff --git a/share/spack/setup-env.sh b/share/spack/setup-env.sh index a8e918c1c9..f82a55d8f1 100755 --- a/share/spack/setup-env.sh +++ b/share/spack/setup-env.sh @@ -236,7 +236,18 @@ export SPACK_ROOT=${_sp_prefix} # Determine which shell is being used # function _spack_determine_shell() { - PS_FORMAT= ps -p $$ | tail -n 1 | awk '{print $4}' | sed 's/^-//' | xargs basename + # This logic is derived from the cea-hpc/modules profile.sh example at + # https://github.com/cea-hpc/modules/blob/master/init/profile.sh.in + # + # The objective is to correctly detect the shell type even when setup-env + # is sourced within a script itself rather than a login terminal. + if [ -n "${BASH:-}" ]; then + echo ${BASH##*/} + elif [ -n "${ZSH_NAME:-}" ]; then + echo $ZSH_NAME + else + PS_FORMAT= ps -p $$ | tail -n 1 | awk '{print $4}' | sed 's/^-//' | xargs basename + fi } export SPACK_SHELL=$(_spack_determine_shell) |