On Wed, May 9, 2012 at 12:57 PM, Chet Ramey
<address@hidden> wrote:
On 5/9/12 1:24 PM, Bill Gradwohl wrote:
> declare -i -a intArray=(' 5' ' 2 ' 1 ' -19 ' 'xyz')
> declare -p intArray
> intArray[0]=' 5'
> declare -p intArray
>
> unset intArray
> declare -i -a intArray
> intArray=(' 5' ' 2 ' 1 ' -19 ' 'xyz')
> declare -i -a
>
>
> Outputs:
> address@hidden ycc# ../tst
> declare -ai intArray='([0]=" 5" [1]=" 2 " [2]="1" [3]=" -19 " [4]="xyz")'
> declare -ai intArray='([0]="5" [1]=" 2 " [2]="1" [3]=" -19 " [4]="xyz")'
> declare -ai intArray='([0]="5" [1]="2" [2]="1" [3]="-19" [4]="0")'
>
> I added the bogus xyz just to see what happens. It was after I noticed that
> when provided at the time of declaration, the array holds elements it would
> not otherwise hold. When the same ( ... ) _expression_ is used to initialize
> the array after the array already exist, you get a completely different
> outcome.
>
> Trying to change the existing [0] which contains ' 5' to exactly the same
> thing instead produces just '5'.
This is unsurprising, since you told the shell you wanted arithmetic
expansion performed at assignment. The potential bug, as you noted,
is that the first line of output is not the same as the third.