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

Re: avoid file not found error with { .. } expansion



Eric Smith wrote:
> What would be the correct invocation for this:
> 
> $ xview {02..19}.*jpg
> zsh: no matches found: 04.*jpg
> 
> in order to avoid the error of files not being found.

The main thing to remember is the mantra `brace expansion is not
globbing'.  When you use braces, all elements are generated regardless.
Here, you get:

  xview 02.*jpg 03.*jpg 04.*jpg  ...  19.*jpg

before globbing kicks in.

Are you simply trying to match a set of numbered files of which you're
pretty sure some are there, but not all?  Then the obvious thing to try
is:

 xview <2-19>.*jpg

There's no special handling for a leading zero here, but it will match
one if present.

If you want to be strict about the numeric format, then you need to keep
the braces.  Luckily, in this case you still have the `*', so the set
of arguments generated are still globbing patterns.  Thus you can get
away with:

  xview {02..19}.*jpg(N)

which turns on the NULL_GLOB option for all the patterns.  Then any that
don't match anything will simply be removed.

What you *might* want in this case is for an error to be caused if and
only if there were no matches to any pattern.  With the form in angle
brackets, that's what you get with your current option settings (since
there is only one pattern).  With the form in braces, you would need to
`setopt csh_null_glob' to get this:

  setopt cshnullglob
  xview {02..19}.*jpg

-- 
Peter Stephenson <pws@xxxxxxx>                  Software Engineer
CSR Ltd., Science Park, Milton Road,
Cambridge, CB4 0WH, UK                          Tel: +44 (0)1223 692070


**********************************************************************
This email and any files transmitted with it are confidential and
intended solely for the use of the individual or entity to whom they
are addressed. If you have received this email in error please notify
the system manager.

This footnote also confirms that this email message has been swept by
MIMEsweeper for the presence of computer viruses.

www.mimesweeper.com
**********************************************************************



Messages sorted by: Reverse Date, Date, Thread, Author