diff options
author | Todd Gamblin <tgamblin@llnl.gov> | 2019-07-03 12:43:13 -0700 |
---|---|---|
committer | Todd Gamblin <tgamblin@llnl.gov> | 2019-07-05 12:54:17 -0700 |
commit | 5686c2a5443bb627edc60e91703bb5c78305e1f6 (patch) | |
tree | 10e6d8296bc08be9f99a80da0704959629eea5d7 /share/spack/setup-env.sh | |
parent | 47e9f7aac9c0418fd1e31e88bd49017c429565db (diff) | |
download | spack-5686c2a5443bb627edc60e91703bb5c78305e1f6.tar.gz spack-5686c2a5443bb627edc60e91703bb5c78305e1f6.tar.bz2 spack-5686c2a5443bb627edc60e91703bb5c78305e1f6.tar.xz spack-5686c2a5443bb627edc60e91703bb5c78305e1f6.zip |
setup-env.sh: make setup scripts work with `set -u`
- Add set -u to the setup-env.sh test script
- Refactor lines in setup-env.sh that tested potentially undefined
variables to use the `[ -z ${var+x} ]` construct
Diffstat (limited to 'share/spack/setup-env.sh')
-rwxr-xr-x | share/spack/setup-env.sh | 12 |
1 files changed, 8 insertions, 4 deletions
diff --git a/share/spack/setup-env.sh b/share/spack/setup-env.sh index c5bd32882d..e0161f21a2 100755 --- a/share/spack/setup-env.sh +++ b/share/spack/setup-env.sh @@ -46,9 +46,12 @@ spack() { emulate -L sh fi - # accumulate initial flags for main spack command + # accumulate flags meant for the main spack command + # the loop condition is unreadable, but it means: + # while $1 is set (while there are arguments) + # and $1 starts with '-' (and the arguments are flags) _sp_flags="" - while [ "${1#-}" != "${1}" ]; do + while [ ! -z ${1+x} ] && [ "${1#-}" != "${1}" ]; do _sp_flags="$_sp_flags $1" shift done @@ -62,8 +65,9 @@ spack() { return fi + # set the subcommand if there is one (if $1 is set) _sp_subcommand="" - if [ -n "$1" ]; then + if [ ! -z ${1+x} ]; then _sp_subcommand="$1" shift fi @@ -102,7 +106,7 @@ spack() { case $_sp_arg in activate) _a="$@" - if [ -z "$1" ] || \ + if [ -z ${1+x} ] || \ [ "${_a#*--sh}" != "$_a" ] || \ [ "${_a#*--csh}" != "$_a" ] || \ [ "${_a#*-h}" != "$_a" ]; |