Skip to content

Commit

Permalink
bash 3.x compatibility; avoid unbound variable error
Browse files Browse the repository at this point in the history
bash 3.x treats ${foo[*]} on an empty array as an unbound variable.
Newer bash 4.x and 5.x does not have this problem.

We can use ${#foo[@]} instead, to check if the array is empty.
  • Loading branch information
pda committed Jun 27, 2020
1 parent 9d306dd commit a944971
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions hooks/environment
Original file line number Diff line number Diff line change
Expand Up @@ -131,10 +131,10 @@ function login_using_aws_ecr_get_login_password() {
fi
account_ids=()
while IFS='' read -r line; do account_ids+=("$line"); done < <(plugin_read_list ACCOUNT_IDS | tr "," "\n")
if [[ -z ${account_ids[*]} ]]; then
if [[ ${#account_ids[@]} -eq 0 ]]; then
account_ids=("$(aws sts get-caller-identity --query Account --output text)")
fi
if [[ -z ${account_ids[*]} ]]; then
if [[ ${#account_ids[@]} -eq 0 ]]; then
echo >&2 "AWS account ID required via plugin config or 'aws sts get-caller-identity'"
exit 1
fi
Expand Down

0 comments on commit a944971

Please sign in to comment.