GNU bug report logs - #30105
Additional "grep" parameter to change the exit code from 1 to 0, even if grep doesn't find pattern

Previous Next

Package: grep;

Reported by: Vasyl Vavrychuk <vvavrychuk <at> gmail.com>

Date: Sun, 14 Jan 2018 05:57:02 UTC

Severity: normal

Done: Paul Eggert <eggert <at> cs.ucla.edu>

Bug is archived. No further changes may be made.

To add a comment to this bug, you must first unarchive it, by sending
a message to control AT debbugs.gnu.org, with unarchive 30105 in the body.
You can then email your comments to 30105 AT debbugs.gnu.org in the normal way.

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#30105; Package grep. (Sun, 14 Jan 2018 05:57:02 GMT) Full text and rfc822 format available.

Acknowledgement sent to Vasyl Vavrychuk <vvavrychuk <at> gmail.com>:
New bug report received and forwarded. Copy sent to bug-grep <at> gnu.org. (Sun, 14 Jan 2018 05:57:02 GMT) Full text and rfc822 format available.

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

From: Vasyl Vavrychuk <vvavrychuk <at> gmail.com>
To: bug-grep <at> gnu.org
Subject: Re: Additional "grep" parameter to change the exit code from 1 to 0, 
 even if grep doesn't find pattern
Date: Sun, 14 Jan 2018 07:21:11 +0200
> > I want to suggest my idea about a additional "grep" parameter which
> > would change the exit code 1 to 0, even when "grep" doesn't find a
> > pattern. I.e. something similar to "-0".
>
> Thanks, but you can avoid triggering your trap
> by appending "|| :" to your grep command.
>
> E.g.,
>
>     grep not-found /dev/null || :
>
> Then, even when grep fails, the shell sees only the successful
> exit code from the ":" (always succeeding) built-in command.

It replaces exit status 2 with success too.
I would like to have an option to return success if nothing is found but
still return fail if error happens.




Information forwarded to bug-grep <at> gnu.org:
bug#30105; Package grep. (Sun, 14 Jan 2018 06:58:02 GMT) Full text and rfc822 format available.

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

From: Paul Eggert <eggert <at> cs.ucla.edu>
To: Vasyl Vavrychuk <vvavrychuk <at> gmail.com>, 30105 <at> debbugs.gnu.org
Subject: Re: bug#30105: Additional "grep" parameter to change the exit code
 from 1 to 0, even if grep doesn't find pattern
Date: Sat, 13 Jan 2018 22:57:27 -0800
Vasyl Vavrychuk wrote:
> I would like to have an option to return success if nothing is found but
> still return fail if error happens.

You can use a shell command like this:

grep PATTERN FILE
test $? -lt 2

I don't see the need for a special grep option to handle this problem.




Reply sent to Paul Eggert <eggert <at> cs.ucla.edu>:
You have taken responsibility. (Sun, 14 Jan 2018 17:17:01 GMT) Full text and rfc822 format available.

Notification sent to Vasyl Vavrychuk <vvavrychuk <at> gmail.com>:
bug acknowledged by developer. (Sun, 14 Jan 2018 17:17:01 GMT) Full text and rfc822 format available.

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

From: Paul Eggert <eggert <at> cs.ucla.edu>
To: Vasyl Vavrychuk <vvavrychuk <at> gmail.com>
Cc: 30105-done <at> debbugs.gnu.org
Subject: Re: bug#30105: Additional "grep" parameter to change the exit code
 from 1 to 0, even if grep doesn't find pattern
Date: Sun, 14 Jan 2018 09:16:41 -0800
Vasyl Vavrychuk wrote:
> Actually I use grep in pipe with
> 
>    set -eo pipefail
> 
> but still there I can do
> 
>    ... | grep exrp || test $? -lt 2 | ...
> 
> Thanks for suggestion.

You're welcome. You'll need to parenthesize of course. Closing the bug.




Information forwarded to bug-grep <at> gnu.org:
bug#30105; Package grep. (Sun, 14 Jan 2018 17:43:02 GMT) Full text and rfc822 format available.

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

From: Vasyl Vavrychuk <vvavrychuk <at> gmail.com>
To: Paul Eggert <eggert <at> cs.ucla.edu>
Cc: 30105 <at> debbugs.gnu.org
Subject: Re: bug#30105: Additional "grep" parameter to change the exit code
 from 1 to 0, even if grep doesn't find pattern
Date: Sun, 14 Jan 2018 18:32:42 +0200
Actually I use grep in pipe with

  set -eo pipefail

but still there I can do

  ... | grep exrp || test $? -lt 2 | ...

Thanks for suggestion.

On Sun, Jan 14, 2018 at 8:57 AM, Paul Eggert <eggert <at> cs.ucla.edu> wrote:
> Vasyl Vavrychuk wrote:
>>
>> I would like to have an option to return success if nothing is found but
>> still return fail if error happens.
>
>
> You can use a shell command like this:
>
> grep PATTERN FILE
> test $? -lt 2
>
> I don't see the need for a special grep option to handle this problem.




bug archived. Request was from Debbugs Internal Request <help-debbugs <at> gnu.org> to internal_control <at> debbugs.gnu.org. (Mon, 12 Feb 2018 12:24:03 GMT) Full text and rfc822 format available.

This bug report was last modified 7 years and 125 days ago.

Previous Next


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