From: Mikael Magnusson <mikachu@gmail.com>
To: Roman Perepelitsa <roman.perepelitsa@gmail.com>
Cc: linuxtechguy@gmail.com, zsh <zsh-users@zsh.org>
Subject: Re: special characters in file names issue
Date: Fri, 10 Nov 2023 15:17:40 +0100 [thread overview]
Message-ID: <CAHYJk3RyOF_+VcfAjZOaffij3bsdA8W8fELrq_StXyFhJ6qBSQ@mail.gmail.com> (raw)
In-Reply-To: <CAN=4vMq6bKP5fh3yu-o1ROmoV=QFsFMnwNPP9wbgX4NgZbfdAQ@mail.gmail.com>
On 11/10/23, Roman Perepelitsa <roman.perepelitsa@gmail.com> wrote:
> On Fri, Nov 10, 2023 at 12:17 AM Jim <linux.tech.guy@gmail.com> wrote:
>>
>> Hi everyone,
>>
>> Using scripts, looking to cleanup duplicate files even if named
>> differently.
>> The issue I ran into is when a file path contains parentheses. '(' or ')'
>>
>> Example File Name: Wallpapers/Web_downloads/05 (1).jpg
>>
>> The following is part of an anonymous function:
>>
>> local E
>> local -a AllFileNames
>> local -A FileNameCkSum
>> ...
>> for E (${(@)AllFileNames}) {
>> [[ -v FileNameCkSum[$E] ]] || FileNameCkSum[$E]=${$(shasum -a 1 $E)[1]} }
>> # line that fails
>> ...
>>
>> AllFileName contains the result of a glob statement.
>>
>> Error Message: (anon):<line no>: invalid subscript
>
> 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.
Not sure why I didn't get this error when testing yesterday, but in
this case you can also avoid it by using the more typical ((
$+dict[$key] )) test instead of [[ -v ...]].
--
Mikael Magnusson
next prev parent reply other threads:[~2023-11-10 14:18 UTC|newest]
Thread overview: 15+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-11-09 23:16 Jim
2023-11-10 5:04 ` Mikael Magnusson
2023-11-10 9:50 ` Roman Perepelitsa
2023-11-10 14:17 ` Mikael Magnusson [this message]
2023-11-10 14:28 ` Roman Perepelitsa
2023-11-11 18:26 ` Jim
2023-11-10 16:33 ` Lawrence Velázquez
2023-11-10 17:02 ` Bart Schaefer
2023-11-10 20:37 ` Roman Perepelitsa
2023-11-11 0:13 ` Bart Schaefer
2023-11-11 17:18 ` Ray Andrews
2023-11-11 18:19 ` Bart Schaefer
2023-11-11 18:52 ` Ray Andrews
2023-11-11 18:26 ` Jim
2023-11-12 0:08 ` Bart Schaefer
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=CAHYJk3RyOF_+VcfAjZOaffij3bsdA8W8fELrq_StXyFhJ6qBSQ@mail.gmail.com \
--to=mikachu@gmail.com \
--cc=linuxtechguy@gmail.com \
--cc=roman.perepelitsa@gmail.com \
--cc=zsh-users@zsh.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this public inbox
https://git.vuxu.org/mirror/zsh/
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).