zsh-users
 help / color / mirror / code / Atom feed
From: Alan Wagner-Krankel <awk@awkwork.com>
To: Zsh Users <zsh-users@zsh.org>
Subject: Inconsistent behavior with comparisons and recursive glob patterns
Date: Tue, 30 Apr 2024 03:14:46 -0500	[thread overview]
Message-ID: <CAGZNKjL2cJhLopFPAFFTewh2cHxX+_L4vMx2Nf9bAS0ud58RBw@mail.gmail.com> (raw)

The results of these conditional expressions using recursive glob
operators were unexpectedly different:

> [[ f0 = **/f? ]] && print true || print false
false
> setopt extendedglob
> [[ f0 = (*/)#f? ]] && print true || print false
true

Since **/ is a shorthand version of (*/)#, it seems like they both
should have returned 'true'. The comparisons behave the same when
there is at least one directory in the path:

> [[ d1/f1 = **/f? ]] && print true || print false
true
> setopt extendedglob
> [[ d1/f1 = (*/)#f? ]] && print true || print false
true

I came across this because it affects the behavior of zmv, via a test
that filters filenames (line 254 in zsh5.9). An example:

> mkdir d1 d1/d2
> touch f0 d1/f1 d1/d2/f2
> print -rl -- **/f?
d1/d2/f2
d1/f1
f0
> autoload zmv
> zmv -n '**/f?' '$f.txt'
mv -- d1/d2/f2 d1/d2/f2.txt
mv -- d1/f1 d1/f1.txt
> zmv -n '(*/)#f?' '$f.txt'
mv -- d1/d2/f2 d1/d2/f2.txt
mv -- d1/f1 d1/f1.txt
mv -- f0 f0.txt

I think both zmv calls should have attempted to update the 'f0' file
in the base directory. Am I missing something?

Thanks,
Awk


             reply	other threads:[~2024-04-30  8:16 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-04-30  8:14 Alan Wagner-Krankel [this message]
2024-04-30 14:11 ` Eric Cook
2024-04-30 18:15   ` 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=CAGZNKjL2cJhLopFPAFFTewh2cHxX+_L4vMx2Nf9bAS0ud58RBw@mail.gmail.com \
    --to=awk@awkwork.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).