Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
Re: Why does this extended glob pattern fail?
- X-seq: zsh-users 16145
- From: Mikael Magnusson <mikachu@xxxxxxxxx>
- To: Ronald Fischer <ynnor@xxxxx>
- Subject: Re: Why does this extended glob pattern fail?
- Date: Wed, 27 Jul 2011 16:11:14 +0200
- Cc: zsh-users@xxxxxxx
- Dkim-signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :cc:content-type; bh=BrkzZMETpFuCzj1RsY6+pFQypVBXcPkypyDrNbWUMoE=; b=dkY1CP3bSk1b3kXIAHmvbjn43r58h7SeoEzbCges4hBXvslirTP7NCZsZIdTs5I1D2 0rweaVBdm6YY66YQ+40uPwF3WTC1+jfbO4lEhe3HJ/LhpAT7ImThFb0IiobrbmG9pNas mHMmfCsYPRyMXrfD1w9g63DMn9b6HfiB7W1k8=
- In-reply-to: <1311774830.29469.2156456149@webmail.messagingengine.com>
- List-help: <mailto:zsh-users-help@zsh.org>
- List-id: Zsh Users List <zsh-users.zsh.org>
- List-post: <mailto:zsh-users@zsh.org>
- Mailing-list: contact zsh-users-help@xxxxxxx; run by ezmlm
- References: <1311774830.29469.2156456149@webmail.messagingengine.com>
On 27 July 2011 15:53, Ronald Fischer <ynnor@xxxxx> wrote:
> In my zsh script, I want to copy all files from a directory, except
> files ending in .log and .png. This is my code:
>
> ....
> setopt extendedglob # makes ^ work in glob pattern
> cp ^$from/*.{log,png} $dest
> ....
>
> However, there are cases when $from has neither .log nor .png files; but
> it DOES contain other files. In this case I get the error message
>
> no matches found: ^/home/...../*.log
>
> I think this has to do with the timing of when interpretation of {....}
> and when globbing is done. Why exactly do I get the error message, and
> how do I code this correctly?
The pattern you've written will never do what you want, because you're
using {,} instead of (|), which means it expands before globbing, to
the two patterns ^*.log ^*.png, the first one will happily match png
files while the second one matches log files. This also causes the
error when one of those don't produce any matches but the other does.
What you want is ^*.(log|png) which should match the correct things.
--
Mikael Magnusson
Messages sorted by:
Reverse Date,
Date,
Thread,
Author