Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > gnu.bash.bug > #11396

Re: quoted compound array assignment deprecated

From Chet Ramey <chet.ramey@case.edu>
Newsgroups gnu.bash.bug
Subject Re: quoted compound array assignment deprecated
Date 2015-08-19 10:07 -0400
Message-ID <mailman.8634.1439997144.904.bug-bash@gnu.org> (permalink)
References <CAAZkfoJJdVc5A9WMmBcUqUMjN=2VBq6rtuoDYVO5iMQDoLjS9Q@mail.gmail.com> <CAAZkfoJyOyo=2zE63OYaZua73E-HCTd4bCmMkJDNzhJ5hgVAgw@mail.gmail.com> <55D38D5C.2050605@case.edu> <1645236.4mLlXIIrB0@smorgbox>

Show all headers | View raw


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    chet@case.edu    http://cnswww.cns.cwru.edu/~chet/

Back to gnu.bash.bug | Previous | Next | Find similar


Thread

Re: quoted compound array assignment deprecated Chet Ramey <chet.ramey@case.edu> - 2015-08-19 10:07 -0400

csiph-web