GNU bug report logs - #28105
Inconsistent exit code with --files-without-match

Previous Next

Package: grep;

Reported by: Anthony Sottile <asottile <at> umich.edu>

Date: Tue, 15 Aug 2017 22:24:01 UTC

Severity: normal

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

Bug is archived. No further changes may be made.

Full log


View this message in rfc822 format

From: help-debbugs <at> gnu.org (GNU bug Tracking System)
To: Paul Eggert <eggert <at> cs.ucla.edu>
Cc: tracker <at> debbugs.gnu.org
Subject: bug#28105: closed (Inconsistent exit code with --files-without-match)
Date: Thu, 17 Aug 2017 21:23:02 +0000
[Message part 1 (text/plain, inline)]
Your message dated Thu, 17 Aug 2017 14:21:59 -0700
with message-id <c4e5444d-111a-c8f9-0f6c-40cde9e39aa1 <at> cs.ucla.edu>
and subject line Re: bug#28105: Inconsistent exit code with --files-without-match
has caused the debbugs.gnu.org bug report #28105,
regarding Inconsistent exit code with --files-without-match
to be marked as done.

(If you believe you have received this mail in error, please contact
help-debbugs <at> gnu.org.)


-- 
28105: http://debbugs.gnu.org/cgi/bugreport.cgi?bug=28105
GNU Bug Tracking System
Contact help-debbugs <at> gnu.org with problems
[Message part 2 (message/rfc822, inline)]
From: Anthony Sottile <asottile <at> umich.edu>
To: bug-grep <at> gnu.org
Subject: Inconsistent exit code with --files-without-match
Date: Tue, 15 Aug 2017 15:01:13 -0700
Given the exit code of `grep` vs. `grep -v`, I expect similar results
when comparing `grep -l` and `grep -L` (`--files-with-matches` /
`--files-without-match`)

For at least `grep` / `grep -v` / `grep -l` when the "search" is
successful, it exits `0` and when the search is unsuccessful it exits
`1`.  `grep -L` (`--files-without-match`) does not follow this pattern
which I believe to be an oversight / bug.

Consider the following:

$ echo hello > f

# Search is for "hello", it matches so exit code is 0
$ grep hello -- f; echo $?
hello
0
# Search is for "hi", it fails to match so the exit code is 1
$ grep hi -- f; echo $?
1

# Search is for not "hi", it matches so exit code is 0
$ grep -v hi -- f; echo $?
hello
0
# Search is for not "hello", it fails to match so the exit code is 1
$ grep -v hello -- f; echo $?
1

# Search is for filenames containing hello, it matches so exit code is 0
$ grep -l hello -- f; echo $?
f
0
# Search is for filenames containing hi, it fails to match so exit code is 1
$ grep -l hi -- f; echo $?
1

# Search is for filenames not containing hi, this search is successful
**but it exits 1**
$ grep -L hi -- f; echo $?
f
1
# Search is for filenames not containing hello, this search fails
**but it exits 0**
$ grep -L hello -- f; echo $?
0

Anthony


[Message part 3 (message/rfc822, inline)]
From: Paul Eggert <eggert <at> cs.ucla.edu>
To: Anthony Sottile <asottile <at> umich.edu>
Cc: 28105-done <at> debbugs.gnu.org
Subject: Re: bug#28105: Inconsistent exit code with --files-without-match
Date: Thu, 17 Aug 2017 14:21:59 -0700
[Message part 4 (text/plain, inline)]
Thanks for the pointer. It looks to me like git-grep's behavior is 
better than grep's, so I installed the attached.


[0001-grep-L-exits-with-status-0-if-a-file-is-selected.patch (text/x-patch, attachment)]

This bug report was last modified 4 years and 278 days ago.

Previous Next


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