Skip to main content
Tweeted twitter.com/StackUnix/status/1169852854854537216
added 601 characters in body
Source Link

Question: Is there a bug in zgrep? Should it be fixed?

Question: Is there a bug in zgrep? Should it be fixed?

: 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 <http://www.gnu.org/licenses/gpl.html>. There is NO WARRANTY, to the extent permitted by law. Written by Jean-loup Gailly. : zgrep -q abc /tmp/foo[12] : echo $? 0 

Hacky Workaround to avoid old/buggy zgrep:

: ( gzcat -f /tmp/foo[12] | grep -q abc ) >&/dev/null  : echo $? 0 

Question: Is there a bug in zgrep? Should it be fixed?

: 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 <http://www.gnu.org/licenses/gpl.html>. There is NO WARRANTY, to the extent permitted by law. Written by Jean-loup Gailly. : zgrep -q abc /tmp/foo[12] : echo $? 0 

Question: Is there a bug in zgrep? Should it be fixed?

: 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 <http://www.gnu.org/licenses/gpl.html>. There is NO WARRANTY, to the extent permitted by law. Written by Jean-loup Gailly. : zgrep -q abc /tmp/foo[12] : echo $? 0 

Hacky Workaround to avoid old/buggy zgrep:

: ( gzcat -f /tmp/foo[12] | grep -q abc ) >&/dev/null  : echo $? 0 
added 601 characters in body
Source Link

Edit: Found a newer machine with zgrep/gzip 1.8 and it doesn't have this problem. So, it seems like my machine is just old. Here's what it looks like on the newer machine:

: 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 <http://www.gnu.org/licenses/gpl.html>. There is NO WARRANTY, to the extent permitted by law. Written by Jean-loup Gailly. : zgrep -q abc /tmp/foo[12] : echo $? 0 

Edit: Found a newer machine with zgrep/gzip 1.8 and it doesn't have this problem. So, it seems like my machine is just old. Here's what it looks like on the newer machine:

: 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 <http://www.gnu.org/licenses/gpl.html>. There is NO WARRANTY, to the extent permitted by law. Written by Jean-loup Gailly. : zgrep -q abc /tmp/foo[12] : echo $? 0 
added 382 characters in body
Source Link

Setup

echo "abc" >/tmp/foo1 echo "def" >/tmp/foo2 cp /tmp/foo1 /tmp/gzfoo1 cp /tmp/foo2 /tmp/gzfoo2 gzip /tmp/gzfoo* 

grep exit status with multiple files and one match is 0

grep -q abc /tmp/foo[12] echo $? 0 

zgrep exit status with multiple unzipped files and one match is 1

zgrep -q abc /tmp/foo[12] echo $? 1 

zgrep exit status with multiple zipped files and one match is 1

zgrep -q abc /tmp/gzfoo[12].gz echo $? 1 

I do see that zgrep is a shell script. And it does seem like if any grep returns non-zero, zgrep returns non-zero as well. Here's my paraphrased excerpt from zgrep:

res=0 for input_file do # ... run grep on input_file ... r=$? ... test $res -lt $r && res=$r done exit $res 

zgrep version is (ancient) 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 <http://www.gnu.org/licenses/gpl.html>. There is NO WARRANTY, to the extent permitted by law. Written by Jean-loup Gailly. 

Also happens with zgrep (gzip) 1.6:

$ /<other_zgrep_path/bin/zgrep --version zgrep (gzip) 1.6 Copyright (C) 2010-2013 Free Software Foundation, Inc. This is free software. You may redistribute copies of it under the terms of the GNU General Public License <http://www.gnu.org/licenses/gpl.html>. There is NO WARRANTY, to the extent permitted by law. Written by Jean-loup Gailly. $ /<other_zgrep_path/bin/zgrep -q abc /tmp/gzfoo[12].gz $ echo $? 1 

Question: Is there a bug in zgrep? Should it be fixed?

Setup

echo "abc" >/tmp/foo1 echo "def" >/tmp/foo2 cp /tmp/foo1 /tmp/gzfoo1 cp /tmp/foo2 /tmp/gzfoo2 gzip /tmp/gzfoo* 

grep exit status with multiple files and one match is 0

grep -q abc /tmp/foo[12] echo $? 0 

zgrep exit status with multiple unzipped files and one match is 1

zgrep -q abc /tmp/foo[12] echo $? 1 

zgrep exit status with multiple zipped files and one match is 1

zgrep -q abc /tmp/gzfoo[12].gz echo $? 1 

I do see that zgrep is a shell script. And it does seem like if any grep returns non-zero, zgrep returns non-zero as well. Here's my paraphrased excerpt from zgrep:

res=0 for input_file do # ... run grep on input_file ... r=$? ... test $res -lt $r && res=$r done exit $res 

Question: Is there a bug in zgrep? Should it be fixed?

Setup

echo "abc" >/tmp/foo1 echo "def" >/tmp/foo2 cp /tmp/foo1 /tmp/gzfoo1 cp /tmp/foo2 /tmp/gzfoo2 gzip /tmp/gzfoo* 

grep exit status with multiple files and one match is 0

grep -q abc /tmp/foo[12] echo $? 0 

zgrep exit status with multiple unzipped files and one match is 1

zgrep -q abc /tmp/foo[12] echo $? 1 

zgrep exit status with multiple zipped files and one match is 1

zgrep -q abc /tmp/gzfoo[12].gz echo $? 1 

I do see that zgrep is a shell script. And it does seem like if any grep returns non-zero, zgrep returns non-zero as well. Here's my paraphrased excerpt from zgrep:

res=0 for input_file do # ... run grep on input_file ... r=$? ... test $res -lt $r && res=$r done exit $res 

zgrep version is (ancient) 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 <http://www.gnu.org/licenses/gpl.html>. There is NO WARRANTY, to the extent permitted by law. Written by Jean-loup Gailly. 

Also happens with zgrep (gzip) 1.6:

$ /<other_zgrep_path/bin/zgrep --version zgrep (gzip) 1.6 Copyright (C) 2010-2013 Free Software Foundation, Inc. This is free software. You may redistribute copies of it under the terms of the GNU General Public License <http://www.gnu.org/licenses/gpl.html>. There is NO WARRANTY, to the extent permitted by law. Written by Jean-loup Gailly. $ /<other_zgrep_path/bin/zgrep -q abc /tmp/gzfoo[12].gz $ echo $? 1 

Question: Is there a bug in zgrep? Should it be fixed?

Source Link
Loading