mirror of
git://sourceware.org/git/bzip2.git
synced 2024-11-23 11:43:28 +08:00
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
This commit is contained in:
parent
33414da1d2
commit
d0b47bde0e
16
bzgrep
Normal file → Executable file
16
bzgrep
Normal file → Executable file
@ -65,8 +65,20 @@ for i do
|
||||
else
|
||||
j=$(echo "$i" | sed 's/\\/&&/g;s/|/\\&/g;s/&/\\&/g')
|
||||
j=`printf "%s" "$j" | tr '\n' ' '`
|
||||
bzip2 -cdfq "$i" | $grep $opt "$pat" | sed "s|^|${j}:|"
|
||||
r=$?
|
||||
# A trick adapted from
|
||||
# https://groups.google.com/forum/#!original/comp.unix.shell/x1345iu10eg/Nn1n-1r1uU0J
|
||||
# that has the same effect as the following bash code:
|
||||
# bzip2 -cdfq "$i" | $grep $opt "$pat" | sed "s|^|${j}:|"
|
||||
# r=${PIPESTATUS[1]}
|
||||
exec 3>&1
|
||||
eval `
|
||||
exec 4>&1 >&3 3>&-
|
||||
{
|
||||
bzip2 -cdfq "$i" 4>&-
|
||||
} | {
|
||||
$grep $opt "$pat" 4>&-; echo "r=$?;" >&4
|
||||
} | sed "s|^|${j}:|"
|
||||
`
|
||||
fi
|
||||
test "$r" -ne 0 && res="$r"
|
||||
done
|
||||
|
Loading…
Reference in New Issue
Block a user