diff --git a/asdf.sh b/asdf.sh index 4d7b2aa5..7a01f5e8 100644 --- a/asdf.sh +++ b/asdf.sh @@ -3,7 +3,7 @@ # For Bash, ${BASH_SOURCE[0]} will be used to obtain this script's path. # For Zsh and others, $0 (the path to the shell or script) will be used. _under="$_" -if [ -z "$ASDF_DIR" ]; then +if [ -z "${ASDF_DIR:-}" ]; then if [ -n "${BASH_SOURCE[0]}" ]; then current_script_path="${BASH_SOURCE[0]}" elif [[ "$_under" == *".sh" ]]; then diff --git a/test/asdf_sh.bats b/test/asdf_sh.bats index 02ff44a6..9e06e154 100644 --- a/test/asdf_sh.bats +++ b/test/asdf_sh.bats @@ -26,6 +26,22 @@ cleaned_path() { [ "$output" != "" ] } +@test "does not error if nounset is enabled" { + result=$( + unset -f asdf + unset ASDF_DIR + PATH=$(cleaned_path) + set -o nounset + + source_asdf_sh + echo $ASDF_DIR + ) + + output=$(echo "$result" | grep "asdf") + [ "$?" -eq 0 ] + [ "$output" != "" ] +} + @test "adds asdf dirs to PATH" { result=$( unset -f asdf