Hello, similar problem like in 'xzgrep' occurs in 'zgrep'.  It should exit
0 when at least one searched file matches.  Reproducer is in original
bugreport:

  https://bugzilla.redhat.com/show_bug.cgi?id=1108085

Pavel
>From 1ae05916285b50daede5491ec1cf50f93a7770a2 Mon Sep 17 00:00:00 2001
From: Pavel Raiskup <prais...@redhat.com>
Date: Thu, 12 Jun 2014 13:28:15 +0200
Subject: [PATCH] zgrep: exit 0 when at least one file matches

Mimic the original grep behavior and return exit_success when
at least one file matches given pattern.

Original bugreport against xz:
https://bugzilla.redhat.com/show_bug.cgi?id=1108085
---
 zgrep.in | 15 +++++++++++++--
 1 file changed, 13 insertions(+), 2 deletions(-)

diff --git a/zgrep.in b/zgrep.in
index 857ea48..45d5657 100644
--- a/zgrep.in
+++ b/zgrep.in
@@ -173,7 +173,9 @@ if test $# -eq 0; then
 fi
 
 exec 3>&1
-res=0
+
+# no file matched yet
+res=1
 
 for i
 do
@@ -218,7 +220,16 @@ do
   )
   r=$?
   test 128 -lt $r && exit $r
+
+  # fail occured previously, nothing worse can happen
+  test $res -gt 1 && continue
+
   test "$gzip_status" -eq 0 || test "$gzip_status" -eq 2 || r=2
-  test $res -lt $r && res=$r
+
+  # still no match
+  test $r -eq 1 && continue
+
+  # 0 == match, >=2 == fail
+  res=$r
 done
 exit $res
-- 
1.9.3

Reply via email to