At 8:17 PM EDT on Oct. 11 Aaron Schrab brought me out of hibernation for this:
> At 09:23 +0930 12 Oct 2000, Brian Salter-Duke <[EMAIL PROTECTED]>
> wrote:
> > On Wed, Oct 11, 2000 at 04:38:31PM -0700, Bruce J.A. Nourish wrote:
> > > > if ps -U $LOGNAME | grep realmutt > /dev/null 
> > > 
> > > Be careful about using grep to search the output of ps. For example
> > > 
> > > $ ps ax | grep lemming
> > > 16004 tty1     S      0:00 grep lemming
> > > 
> > > Y'see? Grep makes a match on its own process.
> > 
> > It works OK on AIX 3.2.5 ps. If you add the -f flag it finds the grep
> > line, but it does'nt without it.

Same here on GNU/Linux (Red Hat 6.2) and Solaris 2.5.1, but ps's options
notoriously vary between flavors of UNIX.
 
> Or you could just make a minor modification to the grep pattern:
> 
>   ps -U $LOGNAME | grep 'r[e]almutt' > /dev/null
> 
> That way grep won't be able to match itself.
 
It works, but I don't understand why.  Shouldn't 'r[e]almutt' just parse to
"realmutt"?

And just to play devil's advocate:  Which costs more: | grep -v grep or 
the difference between grep regex and grep plain_old_string?

Thanks for the tip.

-- 
Cynic, n. A blackguard who sees things as they are, not as they ought to be.
- Ambrose Bierce, The Devil's Dictionary
Robert I. Reid <[EMAIL PROTECTED]>     http://astro.utoronto.ca/~reid/
PGP Key: http://astro.utoronto.ca/~reid/pgp.html

Reply via email to