On 8/18/15 5:05 PM, Dan Douglas wrote:
> Sorry I meant to reply to that thread but ran out of time. I think Stephane's
> eventual proposal was pretty close to what I had in mind but expressed badly.
> I'm not sure why it was eventually decided to deprecate the current system
> entirely but I'm not opposed to the idea - especially if it provides no
> functionality for which there aren't easy workarounds.
Deprecated doesn't mean removed. In this case, the meaning is closer to
discouraged or deemphasized.
Bash understands `declare' as a Posix declaration utility, and does its
best to treat arguments to declare and other declaration utilities
identically to standalone assignment statements. The place where that
breaks down is if a compound array assignment is treated as such by
declare when it would have been treated as a scalar assignment had it
appeared standalone. That's why the warning. It's not an error.
> The only thing I'm actively abusing this for at the moment in scripts I
> actually use is as a way of encoding 2D arrays. It's very much a read-only
> datastructure too.
>
> ~ $ ( key1=foo key2=bar; declare -A a=([foo]='([bar]=baz)') "b=${a[$key1]}"
> typeset -p a b; echo "${b[$key2]}" )
> declare -A a='([foo]="([bar]=baz)" )'
> declare -A b='([bar]="baz" )'
> baz
>
> Any change will likely break this property but I think wrapping it in eval
> gives the same result.
This will continue to work, but with a warning about a potentially
dangerous construct.
--
``The lyf so short, the craft so long to lerne.'' - Chaucer
``Ars longa, vita brevis'' - Hippocrates
Chet Ramey, ITS, CWRU [email protected] http://cnswww.cns.cwru.edu/~chet/