[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: zgrep -<NUM> doesn't work if <NUM> is two digits or greater

From: Jim Meyering
Subject: Re: zgrep -<NUM> doesn't work if <NUM> is two digits or greater
Date: Wed, 15 Aug 2012 07:34:15 +0200

Paul Eggert wrote:
> On 08/07/2012 10:24 AM, Jim Meyering wrote:
>> +    if expr "X$option" : 'X-[0-9]\+$' > /dev/null; then
> This part of the patch is not portable, since '\+' is
> a GNU extension, and its behavior isn't specified by POSIX.

Indeed.  I have to be careful about my reflexes.
I'm too used to being able (in coreutils test suite)
to depend on the behavior of coreutils-provided tools.

> To fix this I installed the following zgrep.in patch.
> This diff is relative to the zgrep.in before the current
> series of patches, since that makes it easier to review.
> The basic idea is to avoid the use of expr here, and
> rely just on shell pattern-matching; that's more efficient
> anyway.
> --- a/zgrep.in
> +++ b/zgrep.in
> @@ -65,7 +65,7 @@ while test $# -ne 0; do
>    optarg=
>    case $option in
> -  (-[0123456789EFGHIKLPRTUVZabchilnoqrsuvwxyz]?*)
> +  (-[0123456789EFGHIKLPRTUVZabchilnoqrsuvwxyz]*[!0123456789]*)
>      arg2=-\'$(expr "X$option" : 'X-.[0-9]*\(.*\)' | sed "$escape")
>      eval "set -- $arg2 "'${1+"$@"}'
>      option=$(expr "X$option" : 'X\(-.[0-9]*\)');;

Yes, that is better.

reply via email to

[Prev in Thread] Current Thread [Next in Thread]