zsh-workers
 help / color / mirror / code / Atom feed
* Regexp type pattern matching
@ 2008-05-08  8:48 Jerry Rocteur
  2008-05-08  9:00 ` Peter Stephenson
  0 siblings, 1 reply; 4+ messages in thread
From: Jerry Rocteur @ 2008-05-08  8:48 UTC (permalink / raw)
  To: zsh-workers

Hi,

I'm runnign a script under Zsh 4.2.6 on Redhat

I'm spawning an egrep to do pattern matching:

if echo ${USER_NAME}|egrep -q "^[prt][0-9]"

But after a while this stops working and I get:
rt_sigsuspend(~[HUP CHLD RTMIN RT_1] <unfinished ...

I've tried to put brackets around it if (echo ${USER_NAME}|egrep -q "^[prt][0-9]")

But it still fails after a while.

>From testing it happens after losts of spawning (The above script never failes under ksh).

I've tried to find examples but how do I do this pattern matching in zsh without using egrep:

if echo ${USER_NAME}|egrep -q "^[prt][0-9]"

I find lots of examples of pattern matching on files but how do i do the above in zsh with using egrep or perl etc. ?


Thanks in advance,

jerry


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

* Re: Regexp type pattern matching
  2008-05-08  8:48 Regexp type pattern matching Jerry Rocteur
@ 2008-05-08  9:00 ` Peter Stephenson
  2008-05-08  9:09   ` Jerry Rocteur
  0 siblings, 1 reply; 4+ messages in thread
From: Peter Stephenson @ 2008-05-08  9:00 UTC (permalink / raw)
  To: Jerry Rocteur; +Cc: zsh-workers

"Jerry Rocteur" wrote:
> Hi,
> 
> I'm runnign a script under Zsh 4.2.6 on Redhat
> 
> I'm spawning an egrep to do pattern matching:
> 
> if echo ${USER_NAME}|egrep -q "^[prt][0-9]"
> 
> But after a while this stops working and I get:
> rt_sigsuspend(~[HUP CHLD RTMIN RT_1] <unfinished ...

It might be worth trying with a more recent version of the shell; there
are a few fixes for job handling.  If you're spawning a *lot* of
processes it might be the one I've just fixed, zsh-users/12815.

> I've tried to find examples but how do I do this pattern matching in zsh with
> out using egrep:
> 
> if echo ${USER_NAME}|egrep -q "^[prt][0-9]"

It's straightforward...

  if [[ $USER_NAME = [prt][0-9]* ]]; then
    ...
  fi

-- 
Peter Stephenson <pws@csr.com>                  Software Engineer
CSR PLC, Churchill House, Cambridge Business Park, Cowley Road
Cambridge, CB4 0WZ, UK                          Tel: +44 (0)1223 692070


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

* Re: Regexp type pattern matching
  2008-05-08  9:00 ` Peter Stephenson
@ 2008-05-08  9:09   ` Jerry Rocteur
  2008-05-08  9:50     ` Stephane Chazelas
  0 siblings, 1 reply; 4+ messages in thread
From: Jerry Rocteur @ 2008-05-08  9:09 UTC (permalink / raw)
  To: Peter Stephenson, zsh-workers

> "Jerry Rocteur" wrote:
>> Hi,
>>
>> I'm runnign a script under Zsh 4.2.6 on Redhat
>>
>> I'm spawning an egrep to do pattern matching:
>>
>> if echo ${USER_NAME}|egrep -q "^[prt][0-9]"
>>
>> But after a while this stops working and I get:
>> rt_sigsuspend(~[HUP CHLD RTMIN RT_1] <unfinished ...
> It might be worth trying with a more recent version of the shell; there
> are a few fixes for job handling.  If you're spawning a *lot* of
> processes it might be the one I've just fixed, zsh-users/12815.

I'll pass that onto the powers that be, thanks.

>> I've tried to find examples but how do I do this pattern matching in zsh with
>> out using egrep:
>>
>> if echo ${USER_NAME}|egrep -q "^[prt][0-9]"
>
> It's straightforward...
>
>   if [[ $USER_NAME = [prt][0-9]* ]]; then
>     ...
>   fi

Oops..

you know I tried that but instead of = I put =~ and it did not work.

Thanks very much for this information I really appreciate it.

Jerry
P.S. Can you please tell me which manual this [[ $USER_NAME = [prt][0-9]* ]] is explained, I looked this morning for a
few hours and I didn't seen anything like this ?


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

* Re: Regexp type pattern matching
  2008-05-08  9:09   ` Jerry Rocteur
@ 2008-05-08  9:50     ` Stephane Chazelas
  0 siblings, 0 replies; 4+ messages in thread
From: Stephane Chazelas @ 2008-05-08  9:50 UTC (permalink / raw)
  To: Jerry Rocteur; +Cc: Peter Stephenson, zsh-workers

On Thu, May 08, 2008 at 11:09:39AM +0200, Jerry Rocteur wrote:
[...]
> >   if [[ $USER_NAME = [prt][0-9]* ]]; then
> >     ...
> >   fi
[...]
> you know I tried that but instead of = I put =~ and it did not work.

=~ works with recent versions of zsh and if you have the
zsh/pcre module, you can use perl-like regexps with setopt
re_match_pcre.

[[ $USER_NAME =~ ^[prt][0-9]* ]]

[[ string = pattern ]]

treats pattern as a zsh globbing shell pattern.

zsh patterns are equivalent to regexp (with additions) when the
extended-glob option is on, only with a different syntax.

Here is a quick table of correspondance:

RE      zsh
.	?
*	#
+	##
?	(<pattern>|)
|	|
()	()
^	implied
$	implied
[]	[]
(i:...) (#i)
...

> Thanks very much for this information I really appreciate it.
> 
> Jerry
> P.S. Can you please tell me which manual this [[ $USER_NAME =
> [prt][0-9]* ]] is explained, I looked this morning for a
> few hours and I didn't seen anything like this ?

If you type "info zsh", then "i", then "condi<Tab><Tab>", you'll
see:

3 completions:
condition, completion style    conditional expression
conditional expressions

Select "conditional expressions"

"i" is for "index". You can do the same with the table of
content with the "g" key. The index works better with version
4.12 and above of info.

You can also search the whole manual (with regexps with 4.12)
with the "s" key.

All the key bindings are fully configurable, so if like me, you
don't like the emacs-like key-binding, you can change it.

In any case, remember that what makes the power of "info" is "i"
and "g" (with <Tab>). With a well written manual like zsh, 99%
of the time, I get to the information I'm looking for in a few
keystrokes.

-- 
Stéphane


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

end of thread, other threads:[~2008-05-08  9:50 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2008-05-08  8:48 Regexp type pattern matching Jerry Rocteur
2008-05-08  9:00 ` Peter Stephenson
2008-05-08  9:09   ` Jerry Rocteur
2008-05-08  9:50     ` Stephane Chazelas

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