[arch-projects] [dbscripts] [PATCH 07/11] test/lib/common.inc: use `grep &>/dev/null` instead of `grep -q`.

Luke Shumaker lukeshu at sbcglobal.net
Fri May 22 01:02:13 UTC 2015


On Sun, 17 May 2015 20:38:33 -0400,
Dave Reisner wrote:
> 
> On Sun, May 17, 2015 at 07:44:15PM -0400, Luke Shumaker wrote:
> > `grep -q` may exit as soon as it finds a match; the program piped in to it
> > might not be finished writing, and consequently print a message about a
> > "write error" to stderr.
> > 
> > I'll add that this is not purely hypothetical--it happened to me while
> > testing.
> 
> The rationale doesn't make sense to me. If the program writing to the
> input side of the pipe is the one throwing the error, why should piping
> grep's output to /dev/null change this?

Because it changes when grep terminates.  With `grep -q` grep
terminates as soon as it finds a match, if we run grep without `-q`,
but send the output to /dev/null then grep doesn't terminate until it
reaches the end of the input.  This is important because if grep hangs
up too early (before the program on the input side finishes), then the
program in the input side encounters a write error, as its destination
no longer exists.

--
Happy hacking,
~ Luke Shumaker


More information about the arch-projects mailing list