summaryrefslogtreecommitdiff
path: root/share/spack/setup-env.sh
diff options
context:
space:
mode:
Diffstat (limited to 'share/spack/setup-env.sh')
-rwxr-xr-xshare/spack/setup-env.sh49
1 files changed, 32 insertions, 17 deletions
diff --git a/share/spack/setup-env.sh b/share/spack/setup-env.sh
index c3d9ef260c..5968c4c016 100755
--- a/share/spack/setup-env.sh
+++ b/share/spack/setup-env.sh
@@ -115,31 +115,44 @@ spack() {
else
case $_sp_arg in
activate)
- _a="$@"
+ # Get --sh, --csh, or -h/--help arguments.
+ # Space needed here becauses regexes start with a space
+ # and `-h` may be the only argument.
+ _a=" $@"
+ # Space needed here to differentiate between `-h`
+ # argument and environments with "-h" in the name.
+ # Also see: https://www.gnu.org/software/bash/manual/html_node/Shell-Parameter-Expansion.html#Shell-Parameter-Expansion
if [ -z ${1+x} ] || \
- [ "${_a#*--sh}" != "$_a" ] || \
- [ "${_a#*--csh}" != "$_a" ] || \
- [ "${_a#*-h}" != "$_a" ];
+ [ "${_a#* --sh}" != "$_a" ] || \
+ [ "${_a#* --csh}" != "$_a" ] || \
+ [ "${_a#* -h}" != "$_a" ] || \
+ [ "${_a#* --help}" != "$_a" ];
then
- # no args or args contain -h/--help, --sh, or --csh: just execute
+ # No args or args contain --sh, --csh, or -h/--help: just execute.
command spack env activate "$@"
else
- # actual call to activate: source the output
+ # Actual call to activate: source the output.
eval $(command spack $_sp_flags env activate --sh "$@")
fi
;;
deactivate)
- _a="$@"
- if [ "${_a#*--sh}" != "$_a" ] || \
- [ "${_a#*--csh}" != "$_a" ];
+ # Get --sh, --csh, or -h/--help arguments.
+ # Space needed here becauses regexes start with a space
+ # and `-h` may be the only argument.
+ _a=" $@"
+ # Space needed here to differentiate between `--sh`
+ # argument and environments with "--sh" in the name.
+ # Also see: https://www.gnu.org/software/bash/manual/html_node/Shell-Parameter-Expansion.html#Shell-Parameter-Expansion
+ if [ "${_a#* --sh}" != "$_a" ] || \
+ [ "${_a#* --csh}" != "$_a" ];
then
- # just execute the command if --sh or --csh are provided
+ # Args contain --sh or --csh: just execute.
command spack env deactivate "$@"
elif [ -n "$*" ]; then
- # any other arguments are an error or help, so just run help
+ # Any other arguments are an error or -h/--help: just run help.
command spack env deactivate -h
else
- # no args: source the output of the command
+ # No args: source the output of the command.
eval $(command spack $_sp_flags env deactivate --sh)
fi
;;
@@ -151,17 +164,19 @@ spack() {
return
;;
"load"|"unload")
- # get --sh, --csh, --help, or -h arguments
- # space is important for -h case to differentiate between `-h`
- # argument and specs with "-h" in package name or variant settings
+ # Get --sh, --csh, -h, or --help arguments.
+ # Space needed here becauses regexes start with a space
+ # and `-h` may be the only argument.
_a=" $@"
+ # Space needed here to differentiate between `-h`
+ # argument and specs with "-h" in the name.
+ # Also see: https://www.gnu.org/software/bash/manual/html_node/Shell-Parameter-Expansion.html#Shell-Parameter-Expansion
if [ "${_a#* --sh}" != "$_a" ] || \
[ "${_a#* --csh}" != "$_a" ] || \
[ "${_a#* -h}" != "$_a" ] || \
[ "${_a#* --help}" != "$_a" ];
then
- # just execute the command if --sh or --csh are provided
- # or if the -h or --help arguments are provided
+ # Args contain --sh, --csh, or -h/--help: just execute.
command spack $_sp_flags $_sp_subcommand "$@"
else
eval $(command spack $_sp_flags $_sp_subcommand --sh "$@" || \