bug-bash
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: This errors in 4.4, did not in 4.2: set -u; declare -A foo; echo ${#


From: Greg Wooledge
Subject: Re: This errors in 4.4, did not in 4.2: set -u; declare -A foo; echo ${#foo[@]}
Date: Wed, 6 Nov 2024 22:25:58 -0500

On Thu, Nov 07, 2024 at 02:38:05 +0000, David Linden wrote:
> Description:
>       This errors in 4.4, did not in 4.2: set -u; declare -A foo; echo 
> ${#foo[@]}
>       How am I supposed to determine that a declared associative array is 
> empty?

The easiest way would be to ensure that the array variable is actually
created:

    set -u; declare -A foo=(); echo "${#foo[@]}"

Without the =() part, declare -A only creates a placeholder, which will
assign the -A flag to a future variable named foo, if one is ever created.
You need an assignment to create the variable.



reply via email to

[Prev in Thread] Current Thread [Next in Thread]