[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [Help-bash] declare -i
From: |
Chet Ramey |
Subject: |
Re: [Help-bash] declare -i |
Date: |
Wed, 09 May 2012 14:57:33 -0400 |
User-agent: |
Mozilla/5.0 (Macintosh; Intel Mac OS X 10.7; rv:11.0) Gecko/20120327 Thunderbird/11.0.1 |
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.
Chet
--
``The lyf so short, the craft so long to lerne.'' - Chaucer
``Ars longa, vita brevis'' - Hippocrates
Chet Ramey, ITS, CWRU address@hidden http://cnswww.cns.cwru.edu/~chet/
- [Help-bash] declare -i, Bill Gradwohl, 2012/05/08
- Re: [Help-bash] declare -i, Dan Douglas, 2012/05/09
- Re: [Help-bash] declare -i, Bill Gradwohl, 2012/05/09
- Re: [Help-bash] declare -i, Bill Gradwohl, 2012/05/09
- Re: [Help-bash] declare -i,
Chet Ramey <=
- Re: [Help-bash] declare -i, Bill Gradwohl, 2012/05/09
- Re: [Help-bash] declare -i, Greg Wooledge, 2012/05/09
- Re: [Help-bash] declare -i, Bill Gradwohl, 2012/05/09
- Re: [Help-bash] declare -i, DJ Mills, 2012/05/09
- Re: [Help-bash] declare -i, Greg Wooledge, 2012/05/09
- Re: [Help-bash] declare -i, Chet Ramey, 2012/05/09
- Re: [Help-bash] declare -i, Bill Gradwohl, 2012/05/09
- Re: [Help-bash] declare -i, Dan Douglas, 2012/05/09
- Re: [Help-bash] declare -i, Greg Wooledge, 2012/05/10
- Re: [Help-bash] declare -i, Bill Gradwohl, 2012/05/10