设置
echo "abc" >/tmp/foo1
echo "def" >/tmp/foo2
cp /tmp/foo1 /tmp/gzfoo1
cp /tmp/foo2 /tmp/gzfoo2
gzip /tmp/gzfoo*多个文件的grep退出状态,一个匹配为0。
grep -q abc /tmp/foo[12]
echo $?
0具有多个解压缩文件且匹配为1的zgrep退出状态
zgrep -q abc /tmp/foo[12]
echo $?
1具有多个压缩文件且匹配为1的zgrep退出状态
zgrep -q abc /tmp/gzfoo[12].gz
echo $?
1我确实看到zgrep是一个shell脚本。看起来,如果任何grep返回非零,zgrep也返回非零。以下是我从zgrep摘录的译文:
res=0
for input_file
do
# ... run grep on input_file ...
r=$?
...
test $res -lt $r && res=$r
done
exit $reszgrep版本为(古) 1.3.12:
$ zgrep --version
zgrep (gzip) 1.3.12
Copyright (C) 2007 Free Software Foundation, Inc.
This is free software. You may redistribute copies of it under the terms of
the GNU General Public License .
There is NO WARRANTY, to the extent permitted by law.
Written by Jean-loup Gailly.zgrep (gzip) 1.6也会发生:
$ /.
There is NO WARRANTY, to the extent permitted by law.
Written by Jean-loup Gailly.
$ /问题: zgrep中有bug吗?应该修好吗?编辑:使用zgrep/gzip 1.8找到了一台更新的机器,它没有这个问题。看来我的机器太旧了。下面是它在新机器上的样子:
: zgrep --version
zgrep (gzip) 1.8
Copyright (C) 2010-2016 Free Software Foundation, Inc.
This is free software. You may redistribute copies of it under the terms of
the GNU General Public License .
There is NO WARRANTY, to the extent permitted by law.
Written by Jean-loup Gailly.
: zgrep -q abc /tmp/foo[12]
: echo $?
0为了避免旧的/错误的zgrep,你要做些简单的解决办法:
: ( gzcat -f /tmp/foo[12] | grep -q abc ) >&/dev/null
: echo $?
0发布于 2019-09-05 19:44:29
您可以从https://savannah.gnu.org/git/?group=gzip获得源代码。在提交d2a1928e5534017456dc8a3b600ba0b30cce4a6e中更改了返回代码:
commit d2a1928e5534017456dc8a3b600ba0b30cce4a6e
Author: Paul Eggert
Date: Thu Jun 12 18:43:08 2014 -0700
zgrep: exit with status 0 if a file matches and there's no trouble
Reported by Pavel Raiskup in: http://bugs.gnu.org/17760
* zgrep.in (res): Treat exit status 0 to be greater than 1.
Also, exit immediately on software configuration error.提交消息包含一个指向错误报告的链接:https://debbugs.gnu.org/cgi/bugreport.cgi?bug=17760
你可以自己检查一下。使用上述提交构建的zgrep:
$ /media/data/gzip-install-newer/bin/zgrep --version
zgrep (gzip) 1.6.17-d2a1
Copyright (C) 2010-2014 Free Software Foundation, Inc.
This is free software. You may redistribute copies of it under the terms of
the GNU General Public License .
There is NO WARRANTY, to the extent permitted by law.
Written by Jean-loup Gailly.
$ /media/data/gzip-install-newer/bin/zgrep -q abc /tmp/foo[12]
$ echo $?
0使用上一次提交构建的zgrep:
$ /media/data/gzip-install/bin/zgrep --version
zgrep (gzip) 1.6.16-ed8c
Copyright (C) 2010-2014 Free Software Foundation, Inc.
This is free software. You may redistribute copies of it under the terms of
the GNU General Public License .
There is NO WARRANTY, to the extent permitted by law.
Written by Jean-loup Gailly.
$ /media/data/gzip-install/bin/zgrep -q abc /tmp/foo[12]
$ echo $?
1https://unix.stackexchange.com/questions/539255
复制相似问题