Skip to content

Commit

Permalink
bash 3.x compatibility; consider array of empty string to be empty
Browse files Browse the repository at this point in the history
  • Loading branch information
pda committed Jun 27, 2020
1 parent a944971 commit 5ac470d
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions hooks/environment
Original file line number Diff line number Diff line change
Expand Up @@ -131,10 +131,12 @@ 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 [[ ${#account_ids[@]} -eq 0 ]]; then
# check if account_ids is empty, or only contains an empty string.
# just testing [[ -z ${account_ids[*]} ]] breaks on bash 3.x if the array is empty.
if [[ ${#account_ids[@]} -eq 0 || -z "${account_ids[*]}" ]]; then
account_ids=("$(aws sts get-caller-identity --query Account --output text)")
fi
if [[ ${#account_ids[@]} -eq 0 ]]; then
if [[ ${#account_ids[@]} -eq 0 || -z "${account_ids[*]}" ]]; 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 5ac470d

Please sign in to comment.