Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

Re: unset "hash[key]" isn't matched with what "key" may be



On Sun, 7 Feb 2016 20:10:48 +0100
Sebastian Gniazdowski <sgniazdowski@xxxxxxxxx> wrote:
> I meant that "$i" iterates over keys of $functions

Ah, you mean

% i='opp+a[' 
% function 'opp+a[' { print Hi; }
% 'opp+a['
Hi
% unset "function[$i]"
unset: function[opp+a[]: invalid parameter name

That's because i is expanded first, so the brackets get confused.  So
you might expect

i='opp+a\['

to work to compensate, but it doesn't.  Nor does

unset 'function[$i]'

since there's no later expansion.

No, I can't see an obvious answer either, and it's not specific to
$functions, it happens with an ordinary hash.   It's not actually clear
to me what the right answer should be.  Somehow you need to make the
key stand out from the surrounding syntax.  Allowing backslash quoting,
which was the next guess, might be the asnswer, but see
http://xkcd.com/1638 for commentary on backslashes.

pws



Messages sorted by: Reverse Date, Date, Thread, Author