diff options
author | Mark Wielaard <mark@klomp.org> | 2019-07-12 01:06:33 +0200 |
---|---|---|
committer | Mark Wielaard <mark@klomp.org> | 2019-07-12 01:15:40 +0200 |
commit | d0b47bde0e2f5bae7502ca55b80ab006523db820 (patch) | |
tree | d95fe95677531aeb944499aeda04f25cbc46202c /bzgrep | |
parent | 33414da1d2bedf2cbe693f0e21fdaef11d221b1d (diff) | |
download | bzip2-d0b47bde0e2f5bae7502ca55b80ab006523db820.tar.gz bzip2-d0b47bde0e2f5bae7502ca55b80ab006523db820.tar.bz2 bzip2-d0b47bde0e2f5bae7502ca55b80ab006523db820.zip |
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
Diffstat (limited to 'bzgrep')
-rwxr-xr-x[-rw-r--r--] | bzgrep | 16 |
1 files changed, 14 insertions, 2 deletions
@@ -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" |
72 | done | 84 | done |