Path: csiph.com!optima2.xanadu-bbs.net!xanadu-bbs.net!news.glorb.com!usenet.stanford.edu!not-for-mail From: Stephane Chazelas Newsgroups: gnu.bash.bug Subject: Re: quoted compound array assignment deprecated Date: Tue, 18 Aug 2015 21:21:25 +0100 Lines: 41 Approved: bug-bash@gnu.org Message-ID: References: NNTP-Posting-Host: lists.gnu.org Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Trace: usenet.stanford.edu 1439929296 24861 208.118.235.17 (18 Aug 2015 20:21:36 GMT) X-Complaints-To: action@cs.stanford.edu Cc: bug-bash To: isabella parakiss Envelope-to: bug-bash@gnu.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=date:from:to:cc:subject:message-id:references:mime-version :content-type:content-disposition:in-reply-to:user-agent; bh=UDIIKvKEFi2RFKKLLUnrTjagnVcV3RH1g5kXVUnqyBw=; b=dYlb9yijIQNn4nqpXmac27Pqpn57Y/t5VbDOeh3BNstgntRV9f/KT8kF/EG0cDGDRb awBWmey1Ri6m79OFFH2QIJ11qrWVnYrL24ngzffWvnPOUvHcMaCm3Knh/7g/sn/Xb7nO 5ITlo1InnpCHfvBjjyCaWiP8GtIWoQfVGclAegaC14i4GsXjxZRAfvqT/qGgUR6TbdJR 0i4OJEM5K7Cp4rBcSB35gotACKHQT/Hmz9sv49G5bzfnlWglcB6w8mQJ5yn89N3jkWFy AYSU0TzS4xjNZeTW5HV5qFathwcYoPHUVVQt9y1treii7H7IaeK4MLUCcYOdbIoSGTZt UzBw== X-Received: by 10.194.89.5 with SMTP id bk5mr16899644wjb.144.1439929287347; Tue, 18 Aug 2015 13:21:27 -0700 (PDT) Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.5.21 (2010-09-15) X-detected-operating-system: by eggs.gnu.org: Error: Malformed IPv6 address (bad octet value). X-Received-From: 2a00:1450:400c:c05::232 X-BeenThere: bug-bash@gnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: Bug reports for the GNU Bourne Again SHell List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Xref: csiph.com gnu.bash.bug:11378 2015-08-17 10:19:00 +0200, isabella parakiss: > 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 typically requires two levels of evaluation. The syntax of "declare" is now more consistent with that of bare assignments and there are fewer cases where "declare" ends up evaluating code that it's not meant to. Here, I'd do: declare -A "arr$var" eval "arr$var"'=([x]=y)' By using "eval" (which has the reputation of being dangerous), you're making it clear that there is that second level of evaluation that one should be careful around (and which is there as well with declare but less obvious). The way you're expecting declare to work is just a disguised eval, it's not any safer than eval. To me, variable declaration should be separate from evaluating code. Ideally, I'd rather "declare" didn't do assignments either (note that it was ksh breaking "export" by allowing assignments and causing confusions between simple commands and assignments that was not there in the Bourne shell). -- Stephane