bug-gnu-utils
[Top][All Lists]
Advanced

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

Re: grep -


From: John Cowan
Subject: Re: grep -
Date: Tue, 12 Feb 2008 00:52:13 -0500
User-agent: Mutt/1.5.13 (2006-08-11)

leondd1995 scripsit:

> However, I unknowingly had an empty file named 'st1-nttd' (a file with
> the same name as one of the hosts I was greping for) while in /root.
> I ran ypcat hosts | grep st[1-4]-nttd, from /root and the output only
> showed 'st1-nttd'.

That's happening because the shell is trying to expand the wildcard
"st[1-4]-nttd".  If there is no file matching that pattern, it's sent
through to grep, which does the right thing.  But if st1-nttd exists
and is the only file matching that pattern, then it is the only thing
sent through to grep.

The cure for such problems is to put single quotes around any grep pattern
containing brackets, asterisk, question mark (which is not special to
grep) or backslash.  That way grep will always see the regular expression
unchanged.

> Is this a bug in grep or am I simply using bad syntax?

Neither.

-- 
The first thing you learn in a lawin' family    John Cowan
is that there ain't no definite answers         address@hidden
to anything.  --Calpurnia in To Kill A Mockingbird




reply via email to

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