zgrep: handle a multi-digit context option like -15
authorJim Meyering <meyering@redhat.com>
Tue, 7 Aug 2012 08:21:55 +0000 (10:21 +0200)
committerJim Meyering <meyering@redhat.com>
Wed, 8 Aug 2012 08:01:54 +0000 (10:01 +0200)
* zgrep.in: Do not malfunction when given an option like -15.
Before, it could end up treating the pattern as a file name:

  $ echo x | gzip | zgrep -15 x
  gzip: x.gz: No such file or directory

* NEWS (Bug fixes): Mention it.
Reported by Dan Bloch via Thomas Bushnell in
https://bugs.launchpad.net/bugs/1032831

NEWS
zgrep.in

diff --git a/NEWS b/NEWS
index ac399944aef81a24559716e2a56c95ac3d61cf51..79c111022b689e6d6a54000fc4570266a932e40a 100644 (file)
--- a/NEWS
+++ b/NEWS
@@ -4,6 +4,10 @@ GNU gzip NEWS                                    -*- outline -*-
 
 ** Bug fixes
 
+  zgrep no longer malfunctions with a multi-digit context option like -15.
+  Now, it passes that option to grep (equivalent to -C15) just as it does
+  for single-digit options. [bug introduced in gzip-1.3.12]
+
   zmore now acts more like 'more', and is more portable to POSIXish hosts.
 
 
index d09bfa7128cfa8d01c705caaf48c8fd3c223e085..abc5847dc3a5ae82a96ad8693a3ac9ea90b92d23 100644 (file)
--- a/zgrep.in
+++ b/zgrep.in
@@ -66,9 +66,13 @@ while test $# -ne 0; do
 
   case $option in
   (-[0123456789EFGHIKLPRTUVZabchilnoqrsuvwxyz]?*)
-    arg2=-\'$(expr "X$option" : 'X-.[0-9]*\(.*\)' | sed "$escape")
-    eval "set -- $arg2 "'${1+"$@"}'
-    option=$(expr "X$option" : 'X\(-.[0-9]*\)');;
+    if expr "X$option" : 'X-[0-9]\+$' > /dev/null; then
+      : # Let a multi-digit, digit-only option like -10 fall through.
+    else
+      arg2=-\'$(expr "X$option" : 'X-.[0-9]*\(.*\)' | sed "$escape")
+      eval "set -- $arg2 "'${1+"$@"}'
+      option=$(expr "X$option" : 'X\(-.[0-9]*\)')
+    fi;;
   (--binary-*=* | --[lm]a*=* | --reg*=*)
     ;;
   (-[ABCDXdefm] | binary-* | --file | --[lm]a* | --reg*)