From dc6196e2a041c022f8382b7e610b095718acccfa Mon Sep 17 00:00:00 2001 From: Jim Meyering Date: Tue, 7 Aug 2012 10:21:55 +0200 Subject: [PATCH] zgrep: handle a multi-digit context option like -15 * 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 | 4 ++++ zgrep.in | 10 +++++++--- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/NEWS b/NEWS index ac39994..79c1110 100644 --- 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. diff --git a/zgrep.in b/zgrep.in index d09bfa7..abc5847 100644 --- 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*) -- 2.47.2