Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
Re: special characters in file names issue
- X-seq: zsh-users 29343
- From: Roman Perepelitsa <roman.perepelitsa@xxxxxxxxx>
- To: Lawrence Velázquez <larryv@xxxxxxx>
- Cc: linuxtechguy@xxxxxxxxx, zsh-users@xxxxxxx
- Subject: Re: special characters in file names issue
- Date: Fri, 10 Nov 2023 21:37:55 +0100
- Archived-at: <https://zsh.org/users/29343>
- In-reply-to: <5792009a-ef88-428c-be93-feeaa23aad7e@app.fastmail.com>
- List-id: <zsh-users.zsh.org>
- References: <CA+rB6GLYBa3RMo+dDwk4FtdQ=HB_ix+g3UWqiVJ7ko6DAAVLdA@mail.gmail.com> <CAN=4vMq6bKP5fh3yu-o1ROmoV=QFsFMnwNPP9wbgX4NgZbfdAQ@mail.gmail.com> <5792009a-ef88-428c-be93-feeaa23aad7e@app.fastmail.com>
On Fri, Nov 10, 2023 at 5:34 PM Lawrence Velázquez <larryv@xxxxxxx> wrote:
>
> 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 [...]
Oh wow! This is very surprising to me.
% foo=x
% bar='$foo'
% typeset -A dict=(x 1)
% [[ -v dict[$bar] ]] && echo 'very surprising'
very surprising
There is also a scarier version of this, which causes execution of an
external command when I don't expect it.
% typeset -A dict
% var='dict[$(print -u2 pwnd)]'
% [[ -v $var ]]
pwnd
Is this intended?
On Fri, Nov 10, 2023 at 6:03 PM Bart Schaefer <schaefer@xxxxxxxxxxxxxxxx> wrote:
>
> Do I misunderstand something about the example?
No, it's my bad misremembering stuff. There was something with
"unset[$key]" where I was unable to make it work for any "$key" but I
cannot recall the specifics. It could have had something to do with
binary data in keys.
> -v has to evaluate the subscript to find the array element [...]
Why does it have to evaluate the subscript? `unset` does not do it,
why would [[ -v .. ]] be different?
Roman.
Messages sorted by:
Reverse Date,
Date,
Thread,
Author