Subject: Re: Re: [ksh93-integration-discuss] CR 6715496 Updated
P2shell/korn93ksh93 SEGVs on array reinitialization
--------
> > "U.V. Ravindra" wrote:
> > >
> > > The final for-loop in the script I supplied to
> > Roland is obviously mis-written.
> > > It should be:
> > >
> > > typeset -i idx=0
> > >
> > > for arg in ${argtype[*]}; do
> > > print "${argtype[$idx]} \t ${argname[$idx]}
> > \t ${argvalue[$idx]}"
> > > ((idx = idx + 1))
> > > done
> >
> > Erm... shouldn't this for-loop iterate over each
> > array element ? If
> > "yes" the loop should AFAIK look like this:
> > -- snip --
> > integer idx
> >
> > for (( idx=0 ; idx < ${!argty...@]} ; idx++ )) ; do
> > printf "%s \t %s \t %s\n" \
> > "${argtype[$idx]}" \
> > "${argname[$idx]}" \
> > "${argvalue[$idx]}"
> > snip --
> >
>
> The answer to your question is "yes", but the loop I provided does the same
> thin
> g; it iterates over each array element. Sure, we could do without
> introducing t
> he extra 'arg' variable, but that's not the point you're making :)
>
> By the way, the "wrong" loop in the script originally supplied ALSO produces
> the
> expected output, but that should be considered another bug in ksh93. When
> idx
> is explicitly declared as integer-typed and argtype is an array containing
> strin
> gs, I would expect the following to fail:
>
>
> for idx in ${argtype[*]}; do
> print ${argtype[$idx]}
> done
>
> Why doesn't ksh93 (Version M 1993-12-28 s+) consider this (or even simply:
> types
> et -i idx="junk") an error?
>
> -UVR.
>
>
${argtype[*]} expands to the values of argtype (which is then split and matched
for files)
Use ${!argtype[*]} or even better "${!argty...@]}" to get the list
of subscripts. This works for associative arrays also
typeset -i idx=0
for idx in "${!argty...@]}"; do
print -r -- "${argtype[$idx]}"
done
David Korn
dgk at research.att.com