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

Re: special characters in file names issue



On Fri, Nov 10, 2023 at 8:34 AM Lawrence Velázquez <larryv@xxxxxxx> wrote:
>
> On Fri, Nov 10, 2023, at 4:50 AM, Roman Perepelitsa wrote:
> >
> > [...] my memory tells
> > me that some keys cannot be made to work under `[[ -v ...]]` or
> > `unset` no matter how you try to escape them. I could be wrong though.

% typeset -A dict
% key='('
% dict=( [\(]=paren )
% typeset -p dict
typeset -A dict=( ['(']=paren )
% unset "dict[$key]"
% typeset -p dict
typeset -A dict=( )
%

Do I misunderstand something about the example?

Roman is however correct that there's no single quoting strategy that
works everywhere you might use an associative array subscript.  You
have to match the quoting to the context.

> Subscripted arguments to [[ -v ... ]] appear to undergo a second
> round of expansions, so quoting "$key" itself should be sufficient.

This makes sense from the implementation standpoint if perhaps not
from user perspective; -v has to evaluate the subscript to find the
array element, and that it has already undergone expansion by
order-of-evaluation in [[ ]] isn't "known".




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