[ubuntu-florida] Avoid That grep Command in grep Output

Miano, Steven M. Steven.Miano at mybrighthouse.com
Wed Sep 15 15:37:44 BST 2010


I've always just done:

$ps aux | grep bash | grep -v grep

Is there something wrong with that?

On the error in the book that's interesting, I wasn't able to reproduce the same error using the same command successively....8.04/LTS/i386

~Steven

________________________________________
From: ubuntu-us-fl-bounces at lists.ubuntu.com [ubuntu-us-fl-bounces at lists.ubuntu.com] On Behalf Of j.e.aneiros [jesus.aneiros at gmail.com]
Sent: Wednesday, September 15, 2010 9:39 AM
To: Mailing list for Ubuntu Florida LoCo Team
Subject: [ubuntu-florida] Avoid That grep Command in grep Output

Hello everyone,

I'm planning to send everyday at least a message to the list with something interesting about Linux. This is the first one.

One week ago I bought the book "Official Ubuntu Server Book, The (2nd Edition)". Being a command line fan I went directly to the section "Cool tips and tricks". I started reading and I found out that the explanation of the first trick is in a certain way wrong.

The idea behind the trick is to avoid the appearance of grep in resulting list for a command like:

janeiros at harlie:~$ ps ax | grep bash
13235 tty1     S      0:00 -bash
13256 tty1     S+     0:00 /bin/bash /usr/bin/startx
16911 pts/0    Ss+    0:00 -bash
17005 pts/1    Ss     0:00 -bash
17152 pts/1    S+     0:00 grep --color=auto bash

The authors suggest a "trick" running the command in this form:

janeiros at harlie:~$ ps ax | grep [b]ash

 How come when I try the trick is OK the first time and wrong at the second one?

janeiros at harlie:~$ ps ax | grep [b]ash
13235 tty1     S      0:00 -bash
13256 tty1     S+     0:00 /bin/bash /usr/bin/startx
16911 pts/0    Ss+    0:00 -bash
17005 pts/1    Ss     0:00 -bash

You can see grep is gone.

And now is back:

janeiros at harlie:~$ ps ax | grep [b]ash
13235 tty1     S      0:00 -bash
13256 tty1     S+     0:00 /bin/bash /usr/bin/startx
16911 pts/0    Ss+    0:00 -bash
17005 pts/1    Ss     0:00 -bash
17185 pts/1    S+     0:00 grep --color=auto bash

Of course, I did something in between that provoked the change! What was it? Let see if somebody find out what was. The authors' explanation for the trick is not exact!

The explanation is right there at the command line!

If nobody finds out I'll tell you later today.

By the way there is an alternative to the trick but it's longer.

Have a good day!

PS. The outputs of the commands weren't edited at all.

--
J. E. Aneiros
GNU/Linux User #190716 en http://counter.li.org
perl -e '$_=pack(c5,0105,0107,0123,0132,(1<<3)+2);y[A-Z][N-ZA-M];print;'
PK fingerprint: 5179 917E 5B34 F073 E11A  AFB3 4CB3 5301 4A80 F674


CONFIDENTIALITY NOTICE: This e-mail may contain information that is privileged, confidential or otherwise protected from disclosure. If you are not the intended recipient of this e-mail, please notify the sender immediately by return e-mail, purge it and do not disseminate or copy it.



More information about the Ubuntu-us-fl mailing list