Subject: Re: bug#21621: Bug | grep | Running in loop

From: Eric Blake <[email-masked]>
Date: Mon, 5 Oct 2015 14:39:56 -0600

tag 21621 notabug
thanks

On 10/05/2015 07:29 AM, Gino Atlas wrote:
> Dear ladies and gentlemen,
> 
> I would like to report a bug.
> When I run this command:
> grep -rl '^PATTERN$'.
> ^C
> (Pay attention to the non-whitespace between pattern and target directory.)
> 
> It seems like it’s running in a loop, though, I was expecting a timeout
> would occur after a while.
> Can you confirm it's a bug and the behaviour is expected?
> 

Yes, that is the expected behavior.  You didn't tell grep what file to
read, so it is defaulting to reading stdin.  But stdin is your terminal,
and grep is waiting for you to type.  When you are done with your input,
type Ctrl-D to tell the terminal to send an EOF to grep, so that it can
quit reading stdin.

Perhaps it could be argued that grep should recognize when its stdin is
a terminal, and issue a warning to the user that they may have forgotten
to specify an input location and to press ctrl-D to break out of grep
waiting for the user to type something.  But GNU Coding Standards
discourage a program behaving differently merely because stdin is a
terminal.

At any rate, since the behavior is intentional, and since grep is
waiting for you to do something (it is NOT burning 100% CPU during that
wait), I'm marking this as not a bug. However, feel free to add more
comments or questions on the topic.

-- 
Eric Blake   eblake redhat com    +1-919-301-3266
Libvirt virtualization library http://libvirt.org