bug-bash
[Top][All Lists]
Advanced

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

Re: +=() can be used to set illegal indices


From: Chet Ramey
Subject: Re: +=() can be used to set illegal indices
Date: Fri, 30 Jun 2023 12:16:46 -0400
User-agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:102.0) Gecko/20100101 Thunderbird/102.12.0

On 6/29/23 6:24 AM, Emanuele Torre wrote:
The fix in the most recent push did not fix the issue:

   $ x=([9223372036854775805]=foo)
   $ x+=( {1..5} )
   $ echo "${x[@]}"
   3 4 5 foo 1 2

It behaves exactly the same way: no error is printed, some elements are
prepended instead of appended, and there are invalid indices in the
output of  declare -p .

Thanks, good catch. The check really needs to be in the loop that goes
through the words in the compound assignment.


What I would have expected was something like this:

   $ x=([9223372036854775805]=foo)
   $ x+=( {1..5} ); echo "this won't run"
   bash: some "invalid assignment" error
   $ declare -p x # no value gets appended since there was an error

No. Why wouldn't the valid assignments be accepted? If you want

a=(1 2 3)

to be as close as possible to

a[0]=1
a[1]=2
a[2]=3

you have to do it that way.

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