bug-bash
[Top][All Lists]
Advanced

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

Re: setarray[unsetkey] doesn't trigger nounset in arithmetic context


From: Chet Ramey
Subject: Re: setarray[unsetkey] doesn't trigger nounset in arithmetic context
Date: Mon, 22 May 2023 17:16:44 -0400
User-agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:102.0) Gecko/20100101 Thunderbird/102.11.0

On 5/21/23 5:01 PM, Martin D Kealey wrote:

1. ${array[@]:start:count} can under some circumstances return elements
with indeces >= start+count, completely contravening expectations from
other programming languages. There should be a `declare` or `local` option
to fix that, and/or a shopt setting.

In the presence of sparse arrays, sure. It's supposed to return `count'
elements, not "the number of elements between array[start] and
array[start+count]." If you want that, isn't it easy enough to initialize
the elements so you don't have a sparse array?

2. ${#array[@]} gives the number of elements rather than the last index
(minus 1). Being able to declare an array as non-sparse (so that all gaps
"exist" with some default value) would fix this.

Again, it seems easy enough to initialize your arrays to whatever default
value you choose if you want this.

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