bug-bash
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: certain strings both legal and illegal as associative array keys


From: Greg Wooledge
Subject: Re: certain strings both legal and illegal as associative array keys
Date: Tue, 10 Mar 2015 08:16:18 -0400
User-agent: Mutt/1.4.2.3i

On Mon, Mar 09, 2015 at 08:18:17PM -0500, vampyrebat@gmail.com wrote:
> This implies to me that escaping the quotes in the unset line would cause the 
> array code to see the same thing in both cases.  That is,
> 
> unset foo[\"a\'b\"]
> 
> would mean that the pre-array code word expansions would result in foo["a'b"] 
> being passed to the array code, the same as what that code sees in the 
> assignment case.

You still have a potential problem with filename expansion (globbing).

imadev:~/tmp$ touch fooa
imadev:~/tmp$ unset foo
imadev:~/tmp$ declare -A foo
imadev:~/tmp$ i="a'b"; foo["$i"]=x
imadev:~/tmp$ fooa=keepme
imadev:~/tmp$ unset foo[\"a\'b\"]
imadev:~/tmp$ declare -p foo fooa
declare -A foo='(["a'\''b"]="x" )'
bash: declare: fooa: not found

Since you need a combination of quotes around the entire argument to
prevent globbing, and quotes inside the argument to preserve the
array index, and a quote that is literally data inside the array index,
it's just a gigantic mess.

That's why I recommended using a variable to store the index.



reply via email to

[Prev in Thread] Current Thread [Next in Thread]