Bug 13151 - Inconsistent exit code with grep -L
Summary: Inconsistent exit code with grep -L
Status: RESOLVED FIXED
Alias: None
Product: Busybox
Classification: Unclassified
Component: Other (show other bugs)
Version: 1.31.x
Hardware: All Linux
: P5 normal
Target Milestone: ---
Assignee: unassigned
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2020-08-12 09:07 UTC by xiechengliang
Modified: 2020-08-14 22:41 UTC (History)
2 users (show)

See Also:
Host:
Target:
Build:


Attachments
Inconsistent exit code with grep -L (1.19 KB, text/plain)
2020-08-12 09:07 UTC, xiechengliang
Details

Note You need to log in before you can comment on or make changes to this bug.
Description xiechengliang 2020-08-12 09:07:52 UTC
Created attachment 8556 [details]
Inconsistent exit code with grep -L

`grep` / `grep -v` / `grep -l` when the "search" is successful, it exits `0` and when the search is unsuccessful it exits `1`. but `grep -L` does not follow this pattern which maybe an oversight or 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

GNU grep had same problem, but now it's fixed. https://lists.gnu.org/archive/html/bug-grep/2017-08/msg00010.html
Comment 1 Denys Vlasenko 2020-08-14 22:41:43 UTC
Fixed in git, thanks