Thanks for reporting that bug. To fix it, I installed the attached patch into
grep master on Savannah.
>From 69a947f97e3389f409946d990820af4b00095fa6 Mon Sep 17 00:00:00 2001
From: Paul Eggert <egg...@cs.ucla.edu>
Date: Sat, 12 Oct 2019 18:31:04 -0700
Subject: [PATCH] =?UTF-8?q?grep:=20fix=20=E2=80=98grep=20-L=20...=20>/dev/?=
=?UTF-8?q?null=E2=80=99=20bug?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
Problem reported by Adam Sampson (Bug#37716).
* NEWS: Mention this.
* src/grep.c (grepdesc): Donât assume that stdout being /dev/null
means list_files == LISTFILES_NONE.
(main): Do not change list_files merely because stdout is /dev/null.
* tests/skip-read: Test for this bug.
---
NEWS | 6 ++++++
src/grep.c | 4 ++--
tests/skip-read | 1 +
3 files changed, 9 insertions(+), 2 deletions(-)
diff --git a/NEWS b/NEWS
index 5cb33cd..9ce65b3 100644
--- a/NEWS
+++ b/NEWS
@@ -2,6 +2,12 @@ GNU grep NEWS -*- outline -*-
* Noteworthy changes in release ?.? (????-??-??) [?]
+** Bug fixes
+
+ The exit status of 'grep -L' is no longer incorrect when standard
+ output is /dev/null.
+ [Bug#37716 introduced in grep 3.2]
+
** Build-related
The build procedure no longer relies on any already-built src/grep
diff --git a/src/grep.c b/src/grep.c
index 4b6b465..6f35f26 100644
--- a/src/grep.c
+++ b/src/grep.c
@@ -1864,7 +1864,7 @@ grepdesc (int desc, bool command_line)
status = !count == !(list_files == LISTFILES_NONMATCHING);
- if (list_files == LISTFILES_NONE)
+ if (list_files == LISTFILES_NONE || dev_null_output)
finalize_input (desc, &st, ineof);
else if (status == 0)
{
@@ -2827,7 +2827,7 @@ main (int argc, char **argv)
/* POSIX says -c, -l and -q are mutually exclusive. In this
implementation, -q overrides -l and -L, which in turn override -c. */
- if (exit_on_match | dev_null_output)
+ if (exit_on_match)
list_files = LISTFILES_NONE;
if ((exit_on_match | dev_null_output) || list_files != LISTFILES_NONE)
{
diff --git a/tests/skip-read b/tests/skip-read
index 3c32c48..2a17334 100755
--- a/tests/skip-read
+++ b/tests/skip-read
@@ -17,6 +17,7 @@ for opts in '-m0 y' '-f /dev/null' '-v ""'; do
done
eval grep -L $opts $matcher /dev/null > out || fail=1
compare exp out || fail=1
+ eval grep -L $opts $matcher /dev/null > /dev/null || fail=1
done
done
--
2.17.1