bug-bash
[Top][All Lists]
Advanced

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

Re: Changing the way bash expands associative array subscripts


From: Léa Gris
Subject: Re: Changing the way bash expands associative array subscripts
Date: Tue, 16 Mar 2021 02:03:32 +0100
User-agent: Telnet/1.0 [tlh] (PDP11/DEC)

Le 16/03/2021 à 01:12, Chet Ramey écrivait :

What do folks think?

Please excuse my profanity of mentioning zsh in this list, but I really think features and behavior convergence can benefit end users in multiple ways, especially when expanding beyond the POSIX sh scope.

What direction has taken zsh with expanding associative array indexes?

I don't know zsh, but I remember in the past, some features have been aligned across shells, and it has proven especially helpful for clarity as an end-user when dealing with non-POSIX shell features

zsh also provide a nice feature to iterate both keys and values in a single loop:

for key value in "${(kv)assoc_array}"; do
    printf '%s -> %s\n' "$key" "$value"
done

which is quite nicer than doing same in bash:

for key in "${!assoc_array[@]}"; do
    value="${assoc_array[$key]}"
    printf '%s -> %s\n' "$key" "$value"
done


I'd love there would be more convergence when this is possible.

--
Léa Gris

Attachment: OpenPGP_signature
Description: OpenPGP digital signature


reply via email to

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