On Wednesday, May 09, 2012 09:07:22 AM Chet Ramey wrote:
> On 5/9/12 3:42 AM, Dan Douglas wrote:
> > Not random. The same behavior affects this more common construct:
> > ~ $ x=y; y=(1 2 3); declare -a "$x"+=(a b c); declare -p y
> >
> > -bash: syntax error near unexpected token `('
> >
> > One would need to know that this triggers declare to treat args as
> > ordinary
> > args and to quote the entire thing as such.
>
> The idea is to treat declare -attribute x=y the same way you would treat
>
> declare -attribute x; x=y
>
> If you want to know whether or not a particular argument will be treated
> as an assignment statement, ask yourself whether it would stand alone as
> an assignment statement.
>
> Posix has taken an initial pass at specifying this behavior; look at
>http://austingroupbugs.net/view.php?id=351#c865 .
>
> Chet
Ah Thanks, I already saw that bug but reading it again I see it pretty well
describes what's going on here.
I suspect the current way of serializing arrays is going to be a complete
train wreck anyway once shells that don't want to add OO extensions (i.e.
typeset name=(typeset ...)) do want to add multidimensional arrays that
support mixed indexed and associative arrays. Mksh is thinking about adding
JSON to work around this... ugh what a mess.
--
Dan Douglas