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

j.e.aneiros jesus.aneiros at gmail.com
Wed Sep 15 14:39:00 BST 2010


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
-------------- next part --------------
An HTML attachment was scrubbed...
URL: https://lists.ubuntu.com/archives/ubuntu-us-fl/attachments/20100915/e2ded782/attachment.htm 


More information about the Ubuntu-us-fl mailing list