NetBSD-Bugs archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
Re: bin/57655: zgrep(1) returns incorrect exit status
The following reply was made to PR bin/57655; it has been noted by GNATS.
From: RVP <rvp%SDF.ORG@localhost>
To: gnats-bugs%netbsd.org@localhost
Cc:
Subject: Re: bin/57655: zgrep(1) returns incorrect exit status
Date: Fri, 13 Oct 2023 23:17:08 +0000 (UTC)
On Thu, 12 Oct 2023, Andreas Gustafsson wrote:
> When zgrep is run with a file argument and the file does not contain
> the given pattern, it incorrectly returns an exit status of 0,
> contrary to what the "EXIT STATUS" section of the zgrep(1) man page
> says.
>
>> How-To-Repeat:
>
> $ >f
> $ grep a f
> $ echo $?
> 1
> $ gzip f
> $ zgrep a f.gz
> $ echo $?
> 0
>
>> Fix:
>
Please try:
```
--- zgrep.orig 2023-10-01 06:55:27.000000000 +0000
+++ zgrep 2023-10-13 23:13:40.742454000 +0000
@@ -111,16 +111,19 @@
then
# ... on stdin
${zcat} -fq - | ${grep} ${grep_args} -- "${pattern}" -
+ rc=$?
else
# ... on all files given on the command line
if [ ${silent} -lt 1 -a $# -gt 1 ]; then
grep_args="-H ${grep_args}"
fi
+ rc=0
while [ $# -gt 0 ]
do
${zcat} -fq -- "$1" | ${grep} --label="${1}" ${grep_args} -- "${pattern}" -
+ [ $? -eq 0 ] || rc=$?
shift
done
fi
-exit 0
+exit $rc
```
-RVP
Home |
Main Index |
Thread Index |
Old Index