[Top][All Lists]

[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: Tue, 30 Mar 2021 10:54:04 -0400
User-agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:78.0) Gecko/20100101 Thunderbird/78.8.1

On 3/29/21 6:40 PM, Eric Cook wrote:
On 3/29/21 5:18 PM, Chet Ramey wrote:
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.

Its just when populating that array dynamically with another array
if that second array didn't contain `v1' hypothetically, the array gets shifted to

OK, how would you do that? What construct would you use in this scenario?

a=( [k1]=k2 [v2]=k3 [v3]= )
which i would imagine to be unexpected for the author of the code and would rather
it error out instead of chugging along.

Wouldn't this be a programming error? If this were a concern, since any
array can have elements with empty values, I would recommend a different
strategy to copy it.

``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]