zgrep: do not assume GNU expr
authorPaul Eggert <eggert@cs.ucla.edu>
Wed, 15 Aug 2012 03:43:16 +0000 (20:43 -0700)
committerPaul Eggert <eggert@cs.ucla.edu>
Wed, 15 Aug 2012 03:43:56 +0000 (20:43 -0700)
* zgrep.in: Do not assume '\+' has the GNU behavior in the BRE
given to 'expr', as POSIX does not guarantee that.  Come to think
of it, use a shell pattern rather than 'expr', as this is more
efficient.

zgrep.in

index abc5847dc3a5ae82a96ad8693a3ac9ea90b92d23..f878acf8197158ab5c6a195c6d15fdf2d02e70c5 100644 (file)
--- a/zgrep.in
+++ b/zgrep.in
@@ -65,14 +65,10 @@ while test $# -ne 0; do
   optarg=
 
   case $option in
-  (-[0123456789EFGHIKLPRTUVZabchilnoqrsuvwxyz]?*)
-    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;;
+  (-[0123456789EFGHIKLPRTUVZabchilnoqrsuvwxyz]*[!0123456789]*)
+    arg2=-\'$(expr "X$option" : 'X-.[0-9]*\(.*\)' | sed "$escape")
+    eval "set -- $arg2 "'${1+"$@"}'
+    option=$(expr "X$option" : 'X\(-.[0-9]*\)');;
   (--binary-*=* | --[lm]a*=* | --reg*=*)
     ;;
   (-[ABCDXdefm] | binary-* | --file | --[lm]a* | --reg*)