bug-bash
[Top][All Lists]
Advanced

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

RE: [EXTERNAL] - Re: This errors in 4.4, did not in 4.2: set -u; declare


From: David Linden
Subject: RE: [EXTERNAL] - Re: This errors in 4.4, did not in 4.2: set -u; declare -A foo; echo ${#foo[@]}
Date: Thu, 7 Nov 2024 05:42:24 +0000

Thanks, and for the quick reply.

Language lawyers...

I'm curious what motivated the change.  Naively it seems creating a placeholder 
for a potential future array keeping track of attributes is more work than just 
creating an empty array.  The change is "surprising" to a user, at least this 
user.

-----Original Message-----
From: Greg Wooledge <greg@wooledge.org> 
Sent: Wednesday, November 6, 2024 10:26 PM
To: David Linden <dlinden@opentext.com>
Cc: bug-bash@gnu.org
Subject: [EXTERNAL] - Re: This errors in 4.4, did not in 4.2: set -u; declare 
-A foo; echo ${#foo[@]}

CAUTION: This email originated from outside of the organization. Do not click 
links or open attachments unless you recognize the sender and know the content 
is safe. If you feel that the email is suspicious, please report it using 
PhishAlarm.


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]