On 5/16/22 08:36, Junio C Hamano wrote:
"GNU grep has been doing so for the past 20 years and existing users
of the command expects '-m 0' to behave that way" is a good enough
reason, especially if '-m 0' is not the only possible way to say
"unlimited".
Yes, I'm inclined in the same direction, now that I see more of the
context. That is, GNU grep can continue what it's long been doing, with
the only change being to the documentation so that we document -m-1 as
meaning "unlimited". This minimizes possible disruption to existing
scripts and satisfies the use case of having a way to turn off any
previously-appearing -m option.
I installed the attached to the GNU grep master doc to do that. Hope
this works for you.From 2deca89cf0c7a99450f88cf0abfadd336511633f Mon Sep 17 00:00:00 2001
From: Paul Eggert <eggert@xxxxxxxxxxx>
Date: Mon, 16 May 2022 12:18:26 -0700
Subject: [PATCH] grep: document -m better
* doc/grep.in.1, doc/grep.texi: Document behavior of -m 0 and -m -1.
This documents longstanding behavior, and is consistent with
how git grep -m will likely behave.
---
doc/grep.in.1 | 10 ++++++++++
doc/grep.texi | 4 ++++
2 files changed, 14 insertions(+)
diff --git a/doc/grep.in.1 b/doc/grep.in.1
index aba085a..5ba90ee 100644
--- a/doc/grep.in.1
+++ b/doc/grep.in.1
@@ -321,6 +321,16 @@ Scanning each input file stops upon first match.
Stop reading a file after
.I NUM
matching lines.
+If
+.I NUM
+is zero,
+.B grep
+stops right away without reading input.
+A
+.I NUM
+of \-1 is treated as infinity and
+.B grep
+does not stop; this is the default.
If the input is standard input from a regular file,
and
.I NUM
diff --git a/doc/grep.texi b/doc/grep.texi
index b9688c8..b073fa7 100644
--- a/doc/grep.texi
+++ b/doc/grep.texi
@@ -341,6 +341,10 @@ Scanning each input file stops upon first match.
@opindex --max-count
@cindex max-count
Stop after the first @var{num} selected lines.
+If @var{num} is zero, @command{grep} stops right away without reading input.
+A @var{num} of @minus{}1 is treated as infinity and @command{grep}
+does not stop; this is the default.
+
If the input is standard input from a regular file,
and @var{num} selected lines are output,
@command{grep} ensures that the standard input is positioned
--
2.34.1