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

Re: Negative Filename Generation



zzapper wrote:
> On Mon, 26 Apr 2004 18:31:00 +0100,  wrote:
> >> >\ls x!([0-9])*
> >> zsh: no matches found: x!([0-9])*
>
> >Did you read the sentence a few lines above the definition of !(...)
> >that starts
> >
> >       If the KSH_GLOB option is set ...
> >
> >?
> unsetopt KSH_GLOB
> 
> Didn't change anything for me

I was asking whether you'd turned it on, not off.   Try reading the
section (and the phrase I quoted) again.  By the way, the equivalent zsh
syntax is x(^[0-9])*.

However, you will run up against a more subtle problem:  !([0-9]) and
(^[0-9]) don't mean `any character which isn't a single digit', they
mean `any *pattern* which isn't a single digit'.  So if the target
filename is something like x123abc, x will match `x', !([0-9]) will
match the empty string and * will match `123abc'.  This is standard UNIX
behaviour, although more confusing than usual here.

You therefore need to tell it that the * shouldn't begin with digits
either.  Actually, the best way is (almost):

ls x(^[0-9]*)

which matches an x, followed by anything which isn't a string starting
with a single digit.  Unfortunately that looks like a glob qualifier to the
matcher, so you need to tell it it isn't:

ls x(^[0-9]*)(|)

does what you want.  The bit at the end just matches a null string, and
since it has `|' in isn't a glob qualifier.  There are other ways of
doing it, including `setopt no_bare_glob_qual'.

There's no simpler way for patterns in general, but this case (with a
single character) obviously simplifies to:

ls x[^0-9]*

-- 
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