bug-bash
[Top][All Lists]
Advanced

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

Re: zsh style associative array assignment bug


From: Chet Ramey
Subject: Re: zsh style associative array assignment bug
Date: Mon, 29 Mar 2021 17:18:17 -0400
User-agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:78.0) Gecko/20100101 Thunderbird/78.8.1

On 3/27/21 5:02 PM, Eric Cook wrote:
Hey,

When doing an assignment with an uneven number of elements bash currently silently treat the last element
as a key and assigns it an empty string.

$ typeset -A ary=(this feature came from zsh); typeset -p ary
declare -A ary=([came]="from" [this]="feature" [zsh]="" )

In zsh this is an error,
% typeset -A ary=(this feature came from zsh); typeset -p ary
zsh: bad set of key/value pairs for associative array

Could bash be adjusted to align with zsh in this case?

I don't think that's a particularly good or elegant aspect of this
syntax to mimic.

If you look at

a=( k1 v1 k2 v2 k3 v3)

as more or less syntactic sugar for

a=( [k1]=v1 [k2]=v2 [k3]=v3 )

it's reasonable that

a=( k1 v1 k2 )

is equivalent to

a=( [k1]=v1 [k2]= ). And that's what bash does.


--
``The lyf so short, the craft so long to lerne.'' - Chaucer
                 ``Ars longa, vita brevis'' - Hippocrates
Chet Ramey, UTech, CWRU    chet@case.edu    http://tiswww.cwru.edu/~chet/



reply via email to

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