[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: quoted compound array assignment deprecated
From: |
isabella parakiss |
Subject: |
Re: quoted compound array assignment deprecated |
Date: |
Tue, 18 Aug 2015 19:52:00 +0200 |
On 8/18/15, Chet Ramey <chet.ramey@case.edu> wrote:
> On 8/17/15 4:19 AM, isabella parakiss wrote:
>> Quoting is necessary in a few cases:
>>
>> $ var=foo; declare -A "arr$var=([x]=y)"
>> bash: warning: arrfoo=([x]=y): quoted compound array assignment
>> deprecated
>> $ var=foo; declare -A arr$var=([x]=y)
>> bash: syntax error near unexpected token `('
>> $ var=foo; declare -A "arr$var"=([x]=y)
>> bash: syntax error near unexpected token `('
>>
>> I don't think this should be the default behaiour...
>
> This is exactly the case for which the warning is intended. If you want
> to construct variable names on the fly, use `eval' or don't mix
> declarations of constructed variable names with compound assignment.
>
> You can read the extensive discussion starting at
> http://lists.gnu.org/archive/html/bug-bash/2014-12/msg00028.html.
>
> http://lists.gnu.org/archive/html/bug-bash/2014-12/msg00115.html is the
> newest proposal.
>
> Chet
> --
> ``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/
>
Sorry for being both pedantic and late for that discussion but what's the
point of this warning? From my understanding, the code is still valid, so
it doesn't stop a possible attacker and it only annoys regular users.
Using eval requires an extra level of escaping on everything else, I'd
rather use declare 2>/dev/null to suppress the warning than eval...
Idea: display the warnings in -n mode, like ksh.
This way bash wouldn't produce unexpected results on existing scripts, it
wouldn't even require a new compatibility level and shopt.
What do you think about it?
---
xoxo iza
Re: quoted compound array assignment deprecated, Stephane Chazelas, 2015/08/18