On Thu, Dec 29, 2011 at 00:11, David Korn <[email protected]> wrote:

> cc: [email protected]
> Subject: Re: [ast-users] [ksh93] typeset -a arr=([k1]=v1 [k2]=v2) bug?
> --------
>
> >
> > $ ksh --version
> >   version         sh (AT&T Research) 93u 2011-02-08
> > $ cat foo.sh
> > typeset -a arr
> > typeset -i k1=0
> > typeset -i k2=1
> > arr=( [k1]=v1 [k2]=v2 )
> > echo ${!arr[@]}
> > $ ksh foo.sh
> > k1 k2    <-- Bug? Should output: 0 1
> > $
> >
> >
>
> This is not a bug, the line
>         arr=( [k1]=v1 [k2]=v2 )
> first unsets arr and then does the assignment.  The assignment creates
> an associative array.
>

This can explain but it's not intuitive and natural I think. At least the
manual should cleary state that the existing variable `arr' is first unset
for cases like this.

>
> However, if you had done
>         typeset -a arr=( [k1]=v1 [k2]=v2 )
> then this would have forced arr to be an indexed array and then the output
> would be 0 1,
>
> David Korn
> [email protected]
>
_______________________________________________
ast-users mailing list
[email protected]
https://mailman.research.att.com/mailman/listinfo/ast-users

Reply via email to