--- Begin Message ---
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
--- End Message ---