GNU bug report logs - #78891
Option to make grep always exit with 0

Previous Next

Package: grep;

Reported by: Thomas Güttler Mailinglisten <guettliml <at> gmail.com>

Date: Tue, 24 Jun 2025 14:36:04 UTC

Severity: normal

Full log


View this message in rfc822 format

From: "Dale R. Worley" <Dale.Worley <at> comcast.net>
To: Thomas Güttler Mailinglisten <guettliml <at> gmail.com>
Cc: 78891 <at> debbugs.gnu.org
Subject: bug#78891: Option to make grep always exit with 0
Date: Wed, 25 Jun 2025 20:49:49 -0400
Thomas Güttler Mailinglisten <guettliml <at> gmail.com> writes:
> Hi Dale, thank you for your reply. Currently, I work around like this:
>
> echo -e "foo\nbar" | { grep '^#' >comments.txt || true; } |
> some-other-command

The difficulty with that code is that it doesn't satisfy the requirement
you stated:

> Afaik there is no option to make `grep` always exit with a zero exit
> status. No matter if a match was found or not. Errors like "file not found"
> should still return a non-zero exit status.

That's why you need the test "$? != 2".

Dale




This bug report was last modified 50 days ago.

Previous Next


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