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

To reply to this bug, email your comments to 68989 AT debbugs.gnu.org.

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#68989; Package grep. (Thu, 08 Feb 2024 08:39:01 GMT) Full text and rfc822 format available.

Acknowledgement sent to Grisha Levit <grishalevit <at> gmail.com>:
New bug report received and forwarded. Copy sent to bug-grep <at> gnu.org. (Thu, 08 Feb 2024 08:39:01 GMT) Full text and rfc822 format available.

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)]

Reply sent to Paul Eggert <eggert <at> cs.ucla.edu>:
You have taken responsibility. (Fri, 09 Feb 2024 09:09:02 GMT) Full text and rfc822 format available.

Notification sent to Grisha Levit <grishalevit <at> gmail.com>:
bug acknowledged by developer. (Fri, 09 Feb 2024 09:09:02 GMT) Full text and rfc822 format available.

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

From: Paul Eggert <eggert <at> cs.ucla.edu>
To: Grisha Levit <grishalevit <at> gmail.com>
Cc: 68989-done <at> debbugs.gnu.org
Subject: Re: bug#68989: grep -m[2+] > /dev/null
Date: Fri, 9 Feb 2024 01:08:24 -0800
[Message part 1 (text/plain, inline)]
Thanks for the bug report. I installed the attached patch; please give 
it a try.
[0001-grep-fix-grep-m2-pattern-file-dev-null.patch (text/x-patch, attachment)]

bug archived. Request was from Debbugs Internal Request <help-debbugs <at> gnu.org> to internal_control <at> debbugs.gnu.org. (Fri, 08 Mar 2024 12:24:10 GMT) Full text and rfc822 format available.

Did not alter fixed versions and reopened. Request was from Debbugs Internal Request <help-debbugs <at> gnu.org> to internal_control <at> debbugs.gnu.org. (Mon, 13 May 2024 07:24:01 GMT) Full text and rfc822 format available.

bug unarchived. Request was from Paul Eggert <eggert <at> cs.ucla.edu> to control <at> debbugs.gnu.org. (Mon, 13 May 2024 07:26:02 GMT) Full text and rfc822 format available.

Did not alter fixed versions and reopened. Request was from Debbugs Internal Request <help-debbugs <at> gnu.org> to internal_control <at> debbugs.gnu.org. (Mon, 13 May 2024 07:26:02 GMT) Full text and rfc822 format available.

Information forwarded to bug-grep <at> gnu.org:
bug#68989; Package grep. (Mon, 13 May 2024 07:28:02 GMT) Full text and rfc822 format available.

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

From: Paul Eggert <eggert <at> cs.ucla.edu>
To: Grisha Levit <grishalevit <at> gmail.com>
Cc: 68989 <at> debbugs.gnu.org
Subject: Re: bug#68989: grep -m[2+] > /dev/null
Date: Mon, 13 May 2024 00:27:19 -0700
On 2024-05-12 22:26, Grisha Levit wrote:

> Just noticed that with this patch grep has extra output when -m is used
> with -[lLq]:
> 
>      $ echo x | grep -l -m1 .
>      x
>      (standard input)
> 
>      $ echo x | grep -q -m1 .
>      x

Thanks for letting us know; I've reopened the bug report.





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.