Just found a bug in pdksh version 5.2.14 – it cannot handle integers arrays correctly (pdksh is the Public Domain Korn Shell). I first discovered this with a lottery script, but actually it is very easy to reproduce:
typeset –i array
array[0]=42
array[1]=43
array[2]=44
array[3]=45
echo "${array[@]}"
gives: 45 45 45 45
This works correctly if typeset –i is not used. Bash, with declare –ia array, works fine, as you might expect.
Subscribe to:
Post Comments (Atom)
2 comments:
And I always used typeset in bash too!
Typeset works in Bash, but declare is preferred. Maybe you should come on our Mastering Bash course? ;-)
Post a Comment