Skip to content

Commit 3fc19af

Browse files
authored
fixing unbound variable (#64)
Using -z in an if statement causes an unbound variable error if set -eu is declared but the variable has not been declared. Changing thing to -n which checks if the variable is declared and/or undefined. undefined is an empty string like bob="" undeclared is if it has never been declared at all
1 parent 1354678 commit 3fc19af

File tree

1 file changed

+1
-1
lines changed
  • modules/bash-commons/src

1 file changed

+1
-1
lines changed

modules/bash-commons/src/aws.sh

+1-1
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ readonly six_hours_in_s=21600
2525
# to consult by setting the environment variable GRUNTWORK_BASH_COMMONS_IMDS_VERSION
2626
# Defaults to IMDSv2 since that is now enabled by default on instances (IMDS only has two options,
2727
# "optional" = both v1 and v2, or "required" = v2 only). All new instances support v2 now.
28-
if [[ -z "$GRUNTWORK_BASH_COMMONS_IMDS_VERSION" ]]; then
28+
if [[ -n "${GRUNTWORK_BASH_COMMONS_IMDS_VERSION}" ]]; then
2929
to_token_or_not_to_token=$(sudo curl -s -o /dev/null -X PUT ${imdsv2_token_endpoint} -H "X-aws-ec2-metadata-token-ttl-seconds: 10"; echo $?)
3030
if [ ${to_token_or_not_to_token} -eq 0 ]; then
3131
default_instance_metadata_version="2"

0 commit comments

Comments
 (0)