[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: grep bug found

From: Paul Jarc
Subject: Re: grep bug found
Date: Sat, 02 Mar 2002 13:39:27 -0500
User-agent: Gnus/5.090006 (Oort Gnus v0.06) Emacs/20.7 (i386-redhat-linux-gnu)

Dennis Lubert <address@hidden> wrote:
> I have found a bug in gnu-grep 2.4.2

No, you've actually found a shell gotcha.

> cat /etc/passwd | cut -d":" -f3 | grep [0-9][0-9][0-9]

[0-9][0-9][0-9] is meaningful to the shell as a filename pattern, as
well as to grep as a regexp.  If any existing files match that
pattern, those names will be substituted in its place, and grep will
be none the wiser.  To ensure that this does not happen, regardless of
whether such files exist, quote the pattern:
cat /etc/passwd | cut -d":" -f3 | grep '[0-9][0-9][0-9]'
Also note the this is a useless use of cat.
cut -d":" -f3 < /etc/passwd | grep '[0-9][0-9][0-9]'
And you could combine the cut and grep commands into a single sed or
awk script.


reply via email to

[Prev in Thread] Current Thread [Next in Thread]