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