GNU bug report logs - #37716
grep exit status with -L redirected to /dev/null

Previous Next

Package: grep;

Reported by: Adam Sampson <ats <at> offog.org>

Date: Sat, 12 Oct 2019 14:23:01 UTC

Severity: normal

Done: Paul Eggert <eggert <at> cs.ucla.edu>

Bug is archived. No further changes may be made.

To add a comment to this bug, you must first unarchive it, by sending
a message to control AT debbugs.gnu.org, with unarchive 37716 in the body.
You can then email your comments to 37716 AT debbugs.gnu.org in the normal way.

Toggle the display of automated, internal messages from the tracker.

View this report as an mbox folder, status mbox, maintainer mbox


Report forwarded to bug-grep <at> gnu.org:
bug#37716; Package grep. (Sat, 12 Oct 2019 14:23:02 GMT) Full text and rfc822 format available.

Acknowledgement sent to Adam Sampson <ats <at> offog.org>:
New bug report received and forwarded. Copy sent to bug-grep <at> gnu.org. (Sat, 12 Oct 2019 14:23:02 GMT) Full text and rfc822 format available.

Message #5 received at submit <at> debbugs.gnu.org (full text, mbox):

From: Adam Sampson <ats <at> offog.org>
To: bug-grep <at> gnu.org
Subject: grep exit status with -L redirected to /dev/null
Date: Sat, 12 Oct 2019 15:22:05 +0100
Hi grep maintainers,

This behaviour, with grep 3.3 built from source, is a bit surprising:

$ echo hello >thing
$ grep -L goodbye thing && echo OK
thing
OK
$ grep -L goodbye thing >/dev/null && echo OK
$

That is, when using -L, redirecting stdout to /dev/null has the same
effect on the exit code as specifying -q (the behaviour with -q is
described in the "Exit Status" section of the manual). This is a bit
awkward if you're using grep in a script, because you don't necessarily
have any control over whether stdout is /dev/null or not.

Cheers,

-- 
Adam Sampson <ats <at> offog.org>                         <http://offog.org/>




Information forwarded to bug-grep <at> gnu.org:
bug#37716; Package grep. (Sat, 12 Oct 2019 22:41:02 GMT) Full text and rfc822 format available.

Message #8 received at submit <at> debbugs.gnu.org (full text, mbox):

From: "Paul Jackson" <pj <at> usa.net>
To: bug-grep <at> gnu.org
Subject: Re: bug#37716: grep exit status with -L redirected to /dev/null
Date: Sat, 12 Oct 2019 17:29:57 -0500
This also happens when doing "grep -L" for something
that -is- in the file, redirected to /dev/null:

======

$ echo hello > thing
$ grep -L hello thing; echo $?
1
$ grep -L hello thing > /dev/null; echo $?
0

=======

My first guess, after a minute glancing at the code, and after
using strace to notice  that grep doesn't even try to invoke
a "write(2)" system call in these examples, if it notices that
its output is redirected to /dev/null, is that the exit status
of the grep command depends sometimes, somehow,  on
whether or not it decided to write out any results at all.

My strace observations in the previous paragraph are probably
reliable.  My guess as to the logic grep is using to determine
it's process exit status are probably not reliable.

-- 
                Paul Jackson
                pj <at> usa.net




Information forwarded to bug-grep <at> gnu.org:
bug#37716; Package grep. (Sat, 12 Oct 2019 23:18:02 GMT) Full text and rfc822 format available.

Message #11 received at submit <at> debbugs.gnu.org (full text, mbox):

From: "Paul Jackson" <pj <at> usa.net>
To: bug-grep <at> gnu.org
Subject: Re: bug#37716: grep exit status with -L redirected to /dev/null
Date: Sat, 12 Oct 2019 18:03:40 -0500
Also it seems that if the output of "grep -L" is redirected
to "/dev/tty", then the exit status of grep is reversed if
also using the "-q" option.

If the output of "grep -L"  is redirected to "/dev/null", then
its exit status polarity is not reversed by the "-q" option.

-- 
                Paul Jackson
                pj <at> usa.net




Reply sent to Paul Eggert <eggert <at> cs.ucla.edu>:
You have taken responsibility. (Sun, 13 Oct 2019 01:34:02 GMT) Full text and rfc822 format available.

Notification sent to Adam Sampson <ats <at> offog.org>:
bug acknowledged by developer. (Sun, 13 Oct 2019 01:34:03 GMT) Full text and rfc822 format available.

Message #16 received at 37716-done <at> debbugs.gnu.org (full text, mbox):

From: Paul Eggert <eggert <at> cs.ucla.edu>
To: Adam Sampson <ats <at> offog.org>
Cc: Paul Jackson <pj <at> usa.net>, 37716-done <at> debbugs.gnu.org
Subject: Re: bug#37716: grep exit status with -L redirected to /dev/null
Date: Sat, 12 Oct 2019 18:33:23 -0700
[Message part 1 (text/plain, inline)]
Thanks for reporting that bug. To fix it, I installed the attached patch into 
grep master on Savannah.
[0001-grep-fix-grep-L-.-dev-null-bug.patch (text/x-patch, attachment)]

Information forwarded to bug-grep <at> gnu.org:
bug#37716; Package grep. (Sun, 13 Oct 2019 19:09:02 GMT) Full text and rfc822 format available.

Message #19 received at 37716-done <at> debbugs.gnu.org (full text, mbox):

From: Jim Meyering <jim <at> meyering.net>
To: Paul Eggert <eggert <at> cs.ucla.edu>
Cc: 37716-done <at> debbugs.gnu.org, Adam Sampson <ats <at> offog.org>
Subject: Re: bug#37716: grep exit status with -L redirected to /dev/null
Date: Sun, 13 Oct 2019 12:07:44 -0700
On Sat, Oct 12, 2019 at 6:34 PM Paul Eggert <eggert <at> cs.ucla.edu> wrote:
> Thanks for reporting that bug. To fix it, I installed the attached patch into
> grep master on Savannah.

Thank you both.
That bug fix is a compelling argument for releasing grep-3.4,
preferably within a month or two
If anyone has pending changes, please post or ping about them.
If you can help triage bug reports, we'd sure appreciate it.




Information forwarded to bug-grep <at> gnu.org:
bug#37716; Package grep. (Sun, 13 Oct 2019 19:19:02 GMT) Full text and rfc822 format available.

Message #22 received at 37716-done <at> debbugs.gnu.org (full text, mbox):

From: Paul Eggert <eggert <at> cs.ucla.edu>
To: Jim Meyering <jim <at> meyering.net>
Cc: 37716-done <at> debbugs.gnu.org, Adam Sampson <ats <at> offog.org>
Subject: Re: bug#37716: grep exit status with -L redirected to /dev/null
Date: Sun, 13 Oct 2019 12:18:14 -0700
On 10/13/19 12:07 PM, Jim Meyering wrote:

> That bug fix is a compelling argument for releasing grep-3.4,
> preferably within a month or two
> If anyone has pending changes, please post or ping about them.
> If you can help triage bug reports, we'd sure appreciate it.

I'll pry loose some time to look at bug reports. Some of them have patches that 
should go in at some point, and I suppose now's as good a time as any unless the 
patch looks risky.




bug archived. Request was from Debbugs Internal Request <help-debbugs <at> gnu.org> to internal_control <at> debbugs.gnu.org. (Mon, 11 Nov 2019 12:24:06 GMT) Full text and rfc822 format available.

This bug report was last modified 5 years and 278 days ago.

Previous Next


GNU bug tracking system
Copyright (C) 1999 Darren O. Benham, 1997,2003 nCipher Corporation Ltd, 1994-97 Ian Jackson.