[Top][All Lists]

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

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

From: vampyrebat
Subject: Re: certain strings both legal and illegal as associative array keys
Date: Mon, 09 Mar 2015 20:18:17 -0500

> these two array subscripts, while
> they appear identical, are not exactly the same:
> foo["a'b"]=two
> unset foo["a'b"]
> The first does not undergo any word expansions before the array
> assignment code runs, so that code performs the appropriate word
> expansions (everything except word splitting and filename generation).
> The second undergoes the usual set of word expansions performed on all
> command arguments, so the array code sees foo[a'b].

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.

However, the net result of this modification is to change the script error 
message from "not a valid identifier" to "bad array subscript".

> At some point, I may take a look at changing this, but it would not be
> backwards compatible, and that is undesirable.  It doesn't help you
> now, either.

Maintaining backwards compatibility while establishing consistent and logical 
behavior is definitely a balancing act!  I have no opinion on this code change. 
 The solution Greg provided solves my problem, and I'm happy with it.

I do believe, however, that the existing documentation provides insufficient 
detail to work out Greg's solution.

reply via email to

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