]> git.ipfire.org Git - thirdparty/xz.git/commitdiff
xzgrep: exit 0 when at least one file matches.
authorLasse Collin <lasse.collin@tukaani.org>
Wed, 11 Jun 2014 17:43:28 +0000 (20:43 +0300)
committerLasse Collin <lasse.collin@tukaani.org>
Tue, 9 Sep 2014 16:18:23 +0000 (19:18 +0300)
Mimic the original grep behavior and return exit_success when
at least one xz compressed file matches given pattern.

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

Thanks to Pavel Raiskup for the patch.

src/scripts/xzgrep.in

index 2bfce19ffb1326ca5c356644b2f21cf2246bb9f2..b927a5590b9e1d994eeaa5bde675604deb388ca8 100644 (file)
@@ -147,7 +147,9 @@ if test $# -eq 0; then
 fi
 
 exec 3>&1
-res=0
+
+# res=1 means that no file matched yet
+res=1
 
 for i; do
   case $i in
@@ -194,8 +196,17 @@ for i; do
     fi >&3 5>&-
   )
   r=$?
+
+  # fail occured previously, nothing worse can happen
+  test $res -gt 1 && continue
+
   test "$xz_status" -eq 0 || test "$xz_status" -eq 2 \
       || test "$(kill -l "$xz_status" 2> /dev/null)" = "PIPE" || 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