zsh-users
 help / color / mirror / code / Atom feed
* something simple (I hope)
@ 2003-08-04 14:33 Andy Spiegl
  2003-08-04 15:10 ` Clint Adams
  2003-08-04 15:12 ` Thomas Köhler
  0 siblings, 2 replies; 9+ messages in thread
From: Andy Spiegl @ 2003-08-04 14:33 UTC (permalink / raw)
  To: ZSH User List

I want to put all files that match the regex pattern
 "^/var/tmp/exec\.[0-9]+$"
into a list that I can then use in a foreach loop.

How can I do that most easily?

Thanks a lot,
 Andy.

-- 
           http://peru.spiegl.de  Our project
      http://radiomaranon.org.pe  Radio Marañón, Jaén, Perú
                              o      _     _         _
  ------- __o       __o      /\_   _ \\o  (_)\__/o  (_)          -o)
  ----- _`\<,_    _`\<,_    _>(_) (_)/<_    \_| \   _|/' \/       /\\
  ---- (_)/ (_)  (_)/ (_)  (_)        (_)   (_)    (_)'  _\o_    _\_v
 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 Today a usual technique is to make a program and then to test it. But: program
 testing can be a very effective way to show the presence of bugs, but it is
 hopelessly inadequate for showing their absence. 
   (Edsger Wybe Dijkstra, The Humble Programmer)


^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: something simple (I hope)
  2003-08-04 14:33 something simple (I hope) Andy Spiegl
@ 2003-08-04 15:10 ` Clint Adams
  2003-08-04 15:12 ` Thomas Köhler
  1 sibling, 0 replies; 9+ messages in thread
From: Clint Adams @ 2003-08-04 15:10 UTC (permalink / raw)
  To: ZSH User List

>  "^/var/tmp/exec\.[0-9]+$"
> into a list that I can then use in a foreach loop.
> 
> How can I do that most easily?

setopt extendedglob
for i in /var/tmp/exec.[0-9]## ; do print $i ; done


^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: something simple (I hope)
  2003-08-04 14:33 something simple (I hope) Andy Spiegl
  2003-08-04 15:10 ` Clint Adams
@ 2003-08-04 15:12 ` Thomas Köhler
  2003-08-04 15:38   ` Andy Spiegl
  1 sibling, 1 reply; 9+ messages in thread
From: Thomas Köhler @ 2003-08-04 15:12 UTC (permalink / raw)
  To: ZSH User List

[-- Attachment #1: Type: text/plain, Size: 657 bytes --]

Andy Spiegl wrote [2003/08/04]:
> I want to put all files that match the regex pattern
>  "^/var/tmp/exec\.[0-9]+$"
> into a list that I can then use in a foreach loop.
> 
> How can I do that most easily?

Not a "foreach" loop, but "for" should work, too:

for i in /var/tmp/exec.[0-9][0-9]* ; do echo $i ; done

> Thanks a lot,
>  Andy.

Ciao,
Thomas

-- 
 Thomas Köhler Email:   jean-luc@picard.franken.de     | LCARS - Linux
     <><        WWW:     http://jeanluc-picard.de      | for Computers
                IRC:             jeanluc               | on All Real
               PGP public key available from Homepage! | Starships

[-- Attachment #2: Type: application/pgp-signature, Size: 189 bytes --]

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: something simple (I hope)
  2003-08-04 15:12 ` Thomas Köhler
@ 2003-08-04 15:38   ` Andy Spiegl
  2003-08-04 15:49     ` Dan Nelson
                       ` (3 more replies)
  0 siblings, 4 replies; 9+ messages in thread
From: Andy Spiegl @ 2003-08-04 15:38 UTC (permalink / raw)
  To: ZSH User List; +Cc: Thomas Köhler

> > I want to put all files that match the regex pattern
> >  "^/var/tmp/exec\.[0-9]+$"
> > into a list that I can then use in a foreach loop.

> for i in /var/tmp/exec.[0-9][0-9]* ; do echo $i ; done
Thanks but I really need a list (with a name).
Actually in the meantime I found out how to do that:
 files=(/var/tmp/exec.[[:digit:]]*)

But what is still bugging me is that this also matches files like
 /var/tmp/exec.01234.something

I can't figure out how to tell zsh that there shouldn't be anything _after_
digits.  What is the zsh-equivalent of a $ in regular expressions?

Thanks again,
 Andy.

-- 
           http://peru.spiegl.de  Our project
      http://radiomaranon.org.pe  Radio Marañón, Jaén, Perú
                              o      _     _         _
  ------- __o       __o      /\_   _ \\o  (_)\__/o  (_)          -o)
  ----- _`\<,_    _`\<,_    _>(_) (_)/<_    \_| \   _|/' \/       /\\
  ---- (_)/ (_)  (_)/ (_)  (_)        (_)   (_)    (_)'  _\o_    _\_v
 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 What do prisoners use to call each other?
 Cell phones.


^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: something simple (I hope)
  2003-08-04 15:38   ` Andy Spiegl
@ 2003-08-04 15:49     ` Dan Nelson
  2003-08-04 15:51     ` Thomas Köhler
                       ` (2 subsequent siblings)
  3 siblings, 0 replies; 9+ messages in thread
From: Dan Nelson @ 2003-08-04 15:49 UTC (permalink / raw)
  To: ZSH User List, Thomas Köhler

In the last episode (Aug 04), Andy Spiegl said:
> > > I want to put all files that match the regex pattern
> > >  "^/var/tmp/exec\.[0-9]+$"
> > > into a list that I can then use in a foreach loop.
> 
> > for i in /var/tmp/exec.[0-9][0-9]* ; do echo $i ; done
> Thanks but I really need a list (with a name).
> Actually in the meantime I found out how to do that:
>  files=(/var/tmp/exec.[[:digit:]]*)
> 
> But what is still bugging me is that this also matches files like
>  /var/tmp/exec.01234.something
> 
> I can't figure out how to tell zsh that there shouldn't be anything _after_
> digits.  What is the zsh-equivalent of a $ in regular expressions?

Your problem isn't the lack of "$" (glob patterns always anchor to the
start and end so ^ and $ operators are unneeded), it's your use of "*". 
"*" in a glob pattern means "match any character", and is equivalent to
the regex ".*" .

Try "/var/tmp/exec.<->".  <-> is the <x-y> numeric range operator with
no minimum or maximum number, so it matches any numeric value.  

The zsh equivalent to the regex "+" is "##", so you could also use
"/var/tmp/exec.[0-9]##" (make sure EXTENDED_GLOB is set).

-- 
	Dan Nelson
	dnelson@allantgroup.com


^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: something simple (I hope)
  2003-08-04 15:38   ` Andy Spiegl
  2003-08-04 15:49     ` Dan Nelson
@ 2003-08-04 15:51     ` Thomas Köhler
  2003-08-04 15:53     ` Bart Schaefer
  2003-08-04 15:55     ` Peter Stephenson
  3 siblings, 0 replies; 9+ messages in thread
From: Thomas Köhler @ 2003-08-04 15:51 UTC (permalink / raw)
  To: ZSH User List

[-- Attachment #1: Type: text/plain, Size: 1230 bytes --]

Andy Spiegl wrote [2003/08/04]:
> > > I want to put all files that match the regex pattern
> > >  "^/var/tmp/exec\.[0-9]+$"
> > > into a list that I can then use in a foreach loop.
> 
> > for i in /var/tmp/exec.[0-9][0-9]* ; do echo $i ; done
> Thanks but I really need a list (with a name).
> Actually in the meantime I found out how to do that:
>  files=(/var/tmp/exec.[[:digit:]]*)
> 
> But what is still bugging me is that this also matches files like
>  /var/tmp/exec.01234.something
> 
> I can't figure out how to tell zsh that there shouldn't be anything _after_
> digits.  What is the zsh-equivalent of a $ in regular expressions?

I have no idea for the "$" problem, but have you tried this?
files=(/var/tmp/exec.<->)
                     ^^^
                     <[n]-[m]> matches any number in the range n
                     to m, both of which are optional...

> Thanks again,
>  Andy.

Ciao,
Thomas

-- 
 Thomas Köhler Email:   jean-luc@picard.franken.de     | LCARS - Linux
     <><        WWW:     http://jeanluc-picard.de      | for Computers
                IRC:             jeanluc               | on All Real
               PGP public key available from Homepage! | Starships

[-- Attachment #2: Type: application/pgp-signature, Size: 189 bytes --]

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: something simple (I hope)
  2003-08-04 15:38   ` Andy Spiegl
  2003-08-04 15:49     ` Dan Nelson
  2003-08-04 15:51     ` Thomas Köhler
@ 2003-08-04 15:53     ` Bart Schaefer
  2003-08-04 15:55     ` Peter Stephenson
  3 siblings, 0 replies; 9+ messages in thread
From: Bart Schaefer @ 2003-08-04 15:53 UTC (permalink / raw)
  To: ZSH User List

On Aug 4,  5:38pm, Andy Spiegl wrote:
} Subject: Re: something simple (I hope)
}
} > > I want to put all files that match the regex pattern
} > >  "^/var/tmp/exec\.[0-9]+$"
} > > into a list that I can then use in a foreach loop.
} 
} Actually in the meantime I found out how to do that:
}  files=(/var/tmp/exec.[[:digit:]]*)
} 
} But what is still bugging me is that this also matches files like
}  /var/tmp/exec.01234.something
} 
} I can't figure out how to tell zsh that there shouldn't be anything _after_
} digits.  What is the zsh-equivalent of a $ in regular expressions?

All glob patterns are implicitly anchored at start and end; there's no
such thing as a file glob that matches anywhere in a file name.

What you've forgotten is that * in a glob pattern is equivalent to .*
in a regular expression.  It's # in zsh that repeats the preceeding
glob pattern.  So what you want is

setopt extendedglob
files=( /var/tmp/exec.[[:digit:]]# )


^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: something simple (I hope)
  2003-08-04 15:38   ` Andy Spiegl
                       ` (2 preceding siblings ...)
  2003-08-04 15:53     ` Bart Schaefer
@ 2003-08-04 15:55     ` Peter Stephenson
  2003-08-04 16:01       ` Andy Spiegl
  3 siblings, 1 reply; 9+ messages in thread
From: Peter Stephenson @ 2003-08-04 15:55 UTC (permalink / raw)
  To: ZSH User List

Andy Spiegl wrote:
> Actually in the meantime I found out how to do that:
>  files=(/var/tmp/exec.[[:digit:]]*)
> 
> But what is still bugging me is that this also matches files like
>  /var/tmp/exec.01234.something
> 
> I can't figure out how to tell zsh that there shouldn't be anything _after_
> digits.  What is the zsh-equivalent of a $ in regular expressions?

The answer to the question you've just asked is `(#e) with the
extendedglob option set'.  However, this doesn't get you very far here.
The answer to the question you should have asked is one of the
following:

  files=(/var/tmp/exec.<->)

or if you're really attached to [[:digit:]]:

  setopt extendedglob
  files=(/var/tmp/exec.[[:digit:]]##)

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


**********************************************************************
The information transmitted is intended only for the person or
entity to which it is addressed and may contain confidential 
and/or privileged material. 
Any review, retransmission, dissemination or other use of, or
taking of any action in reliance upon, this information by 
persons or entities other than the intended recipient is 
prohibited.  
If you received this in error, please contact the sender and 
delete the material from any computer.
**********************************************************************


^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: something simple (I hope)
  2003-08-04 15:55     ` Peter Stephenson
@ 2003-08-04 16:01       ` Andy Spiegl
  0 siblings, 0 replies; 9+ messages in thread
From: Andy Spiegl @ 2003-08-04 16:01 UTC (permalink / raw)
  To: ZSH User List

>   files=(/var/tmp/exec.<->)
That did it!  Thanks a lot.
 Andy.

-- 
           http://peru.spiegl.de  Our project
      http://radiomaranon.org.pe  Radio Marañón, Jaén, Perú
                              o      _     _         _
  ------- __o       __o      /\_   _ \\o  (_)\__/o  (_)          -o)
  ----- _`\<,_    _`\<,_    _>(_) (_)/<_    \_| \   _|/' \/       /\\
  ---- (_)/ (_)  (_)/ (_)  (_)        (_)   (_)    (_)'  _\o_    _\_v
 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 If you steal from one author, it's plagiarism;
 if you steal from many, it's research.  (Wilson Milner)


^ permalink raw reply	[flat|nested] 9+ messages in thread

end of thread, other threads:[~2003-08-04 16:32 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2003-08-04 14:33 something simple (I hope) Andy Spiegl
2003-08-04 15:10 ` Clint Adams
2003-08-04 15:12 ` Thomas Köhler
2003-08-04 15:38   ` Andy Spiegl
2003-08-04 15:49     ` Dan Nelson
2003-08-04 15:51     ` Thomas Köhler
2003-08-04 15:53     ` Bart Schaefer
2003-08-04 15:55     ` Peter Stephenson
2003-08-04 16:01       ` Andy Spiegl

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