GNU bug report logs - #68989
grep -m[2+] > /dev/null

Previous Next

Package: grep;

Reported by: Grisha Levit <grishalevit <at> gmail.com>

Date: Thu, 8 Feb 2024 08:39:01 UTC

Severity: normal

Full log


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

From: Grisha Levit <grishalevit <at> gmail.com>
To: bug-grep <at> gnu.org
Subject: grep -m[2+] > /dev/null
Date: Thu, 8 Feb 2024 03:37:24 -0500
[Message part 1 (text/plain, inline)]
This example file will require multiple reads:

$ printf '%07d\n' {0..98304} > txt

When limiting the match count to 1, the input offset is correctly restored
before grep exits,  no matter the output:

$ { grep -m1 . >/dev/zero; head -n1; } < txt
0000001
$ { grep -m1 . >/dev/null; head -n1; } < txt
0000001

If the count is 2 or higher, this also works, unless the output is being
discarded to /dev/null -- in this case not only is the input offset not
restored, but the entire file is consumed:

$ { grep -m2 . >/dev/zero; head -n1; } < txt
0000002
$ { grep -m2 . >/dev/null; head -n1; } < txt
$
[Message part 2 (text/html, inline)]

This bug report was last modified 1 year and 33 days ago.

Previous Next


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