Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

Re: Why does this extended glob pattern fail?

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