Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
Re: special characters in file names issue
- X-seq: zsh-users 29340
- From: Lawrence Velázquez <larryv@xxxxxxx>
- To: "Roman Perepelitsa" <roman.perepelitsa@xxxxxxxxx>, linuxtechguy@xxxxxxxxx
- Cc: zsh-users@xxxxxxx
- Subject: Re: special characters in file names issue
- Date: Fri, 10 Nov 2023 11:33:35 -0500
- Archived-at: <https://zsh.org/users/29340>
- Feedback-id: iaa214773:Fastmail
- In-reply-to: <CAN=4vMq6bKP5fh3yu-o1ROmoV=QFsFMnwNPP9wbgX4NgZbfdAQ@mail.gmail.com>
- List-id: <zsh-users.zsh.org>
- References: <CA+rB6GLYBa3RMo+dDwk4FtdQ=HB_ix+g3UWqiVJ7ko6DAAVLdA@mail.gmail.com> <CAN=4vMq6bKP5fh3yu-o1ROmoV=QFsFMnwNPP9wbgX4NgZbfdAQ@mail.gmail.com>
On Fri, Nov 10, 2023, at 4:50 AM, Roman Perepelitsa wrote:
> Associative arrays in zsh are finicky when it comes to the content of
> their keys. The problem you are experiencing can be distilled to this:
>
> % typeset -A dict
> % key='('
> % [[ -v dict[$key] ]]
> zsh: invalid subscript
>
> There is no simple quoting that you can apply to $key here: (q), (b),
> etc. are all wrong. You could perhaps escape a specific list of
> characters ('(', '[', '{' but not '$' or '*') although 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.
Subscripted arguments to [[ -v ... ]] appear to undergo a second
round of expansions, so quoting "$key" itself should be sufficient.
% typeset -A dict=('(' foo)
% key='('
% [[ -v dict[\$key] ]]; echo $?
0
% [[ -v dict['$key'] ]]; echo $?
0
% [[ -v 'dict[$key]' ]]; echo $?
0
--
vq
Messages sorted by:
Reverse Date,
Date,
Thread,
Author