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.
This commit is contained in:
		 Phil Carns
					Phil Carns
				
			
				
					committed by
					
						 Peter Scheibel
						Peter Scheibel
					
				
			
			
				
	
			
			
			 Peter Scheibel
						Peter Scheibel
					
				
			
						parent
						
							8ca384875e
						
					
				
				
					commit
					6971f8ae32
				
			| @@ -236,7 +236,18 @@ export SPACK_ROOT=${_sp_prefix} | ||||
| # Determine which shell is being used | ||||
| # | ||||
| function _spack_determine_shell() { | ||||
|     # 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) | ||||
|  | ||||
|   | ||||
		Reference in New Issue
	
	Block a user