summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMark Wielaard <mark@klomp.org>2019-07-12 01:06:33 +0200
committerMark Wielaard <mark@klomp.org>2019-07-12 01:15:40 +0200
commitd0b47bde0e2f5bae7502ca55b80ab006523db820 (patch)
treed95fe95677531aeb944499aeda04f25cbc46202c
parentFix bashism in bzgrep (diff)
downloadbzip2-d0b47bde0e2f5bae7502ca55b80ab006523db820.tar.gz
bzip2-d0b47bde0e2f5bae7502ca55b80ab006523db820.tar.bz2
bzip2-d0b47bde0e2f5bae7502ca55b80ab006523db820.tar.xz
Fix bzgrep so it doesn't always return a 0 exit code with multiple archives
The bzgrep wrapper always returns 0 as exit code when working on multiple archives, even when the pattern is not found. Fix from openSUSE by Kristýna Streitová <kstreitova@suse.com> https://bugzilla.suse.com/970260
-rwxr-xr-x[-rw-r--r--]bzgrep16
1 files changed, 14 insertions, 2 deletions
diff --git a/bzgrep b/bzgrep
index 5080afd..0314ca6 100644..100755
--- a/bzgrep
+++ b/bzgrep
@@ -65,8 +65,20 @@ for i do
65 else 65 else
66 j=$(echo "$i" | sed 's/\\/&&/g;s/|/\\&/g;s/&/\\&/g') 66 j=$(echo "$i" | sed 's/\\/&&/g;s/|/\\&/g;s/&/\\&/g')
67 j=`printf "%s" "$j" | tr '\n' ' '` 67 j=`printf "%s" "$j" | tr '\n' ' '`
68 bzip2 -cdfq "$i" | $grep $opt "$pat" | sed "s|^|${j}:|" 68 # A trick adapted from
69 r=$? 69 # https://groups.google.com/forum/#!original/comp.unix.shell/x1345iu10eg/Nn1n-1r1uU0J
70 # that has the same effect as the following bash code:
71 # bzip2 -cdfq "$i" | $grep $opt "$pat" | sed "s|^|${j}:|"
72 # r=${PIPESTATUS[1]}
73 exec 3>&1
74 eval `
75 exec 4>&1 >&3 3>&-
76 {
77 bzip2 -cdfq "$i" 4>&-
78 } | {
79 $grep $opt "$pat" 4>&-; echo "r=$?;" >&4
80 } | sed "s|^|${j}:|"
81 `
70 fi 82 fi
71 test "$r" -ne 0 && res="$r" 83 test "$r" -ne 0 && res="$r"
72done 84done