zsh-users
 help / color / mirror / code / Atom feed
From: Vincent Lefevre <vincent@vinc17.net>
To: zsh-users@zsh.org
Subject: glob qualifier on intermediate directory / no symbolic links
Date: Wed, 10 Jul 2019 15:37:31 +0200	[thread overview]
Message-ID: <20190710133731.GA13596@cventin.lip.ens-lyon.fr> (raw)

Is there a way to use a glob qualifier on an intermediate directory?
At least, avoid symbolic links from being followed.

For instance, with:

% mkdir -p dir/dir2
% ln -s dir foo
% touch {dir,dir/dir2}/file

With recursive globbing, one can choose whether or not to follow
symbolic links:

% echo **/file
dir/dir2/file dir/file

% echo ***/file
dir/dir2/file dir/file foo/dir2/file foo/file

Without recursive globbing, * matches symbolic links:

% echo */file
dir/file foo/file

But what if I don't want to match symbolic links?

At the end of a pattern, (^@) can be used:

% echo *
dir foo

% echo *(^@)
dir

but not inside a pattern:

% echo *(^@)/file
zsh: no matches found: *(^@)/file

With EXTENDED_GLOB, I get both, like */file, because (...) is used
here for grouping, not for a glob qualifier.

% setopt EXTENDED_GLOB
% echo *(^@)/file
dir/file foo/file

I would have expected the following to work, but doesn't.

% echo (*(^@))/file
dir/file foo/file

The zshexpn(1) man page says:

    Glob Qualifiers
        Patterns used for filename generation may end in a list of
        qualifiers enclosed in parentheses. [...]

What "patterns" means here is not clear. Above, one has

    (...)  Matches the enclosed pattern. [...]
                                ^^^^^^^

but it seems that this is not a pattern that can have a glob qualifier.
I assume that except for the grouping exception and recursive globbing,
this is because patterns are mainly string operations until the list of
files before considering glob qualifiers is obtained.

I'm wondering why the following is not accepted:

% echo (*/)file
zsh: bad pattern: (*/)file

I think that (pat/) without a following # should match a single
occurrence of pat/ (without following symbolic links, contrary
to the case without parentheses).

-- 
Vincent Lefèvre <vincent@vinc17.net> - Web: <https://www.vinc17.net/>
100% accessible validated (X)HTML - Blog: <https://www.vinc17.net/blog/>
Work: CR INRIA - computer arithmetic / AriC project (LIP, ENS-Lyon)

             reply	other threads:[~2019-07-10 13:38 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-07-10 13:37 Vincent Lefevre [this message]
2019-07-10 13:58 ` Pier Paolo Grassi
2019-07-10 16:26   ` Mikael Magnusson
2019-07-12  8:20   ` Vincent Lefevre
     [not found]   ` <20190712082023.GA3983__17556.0249060922$1562919714$gmane$org@zira.vinc17.org>
2019-07-21 21:40     ` Stephane Chazelas
     [not found]   ` <CAHYJk3QJO8XGhJoKVFWugV6pnMDzPs8C=NmYPWQheBUooexv0w__28304.959919636$1562776081$gmane$org@mail.gmail.com>
2019-07-21 21:56     ` Stephane Chazelas

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=20190710133731.GA13596@cventin.lip.ens-lyon.fr \
    --to=vincent@vinc17.net \
    --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).