GNU bug report logs - #19953
egrep: 'Invalid range end' - bug or not?

Previous Next

Package: coreutils;

Reported by: George Shuklin <george.shuklin <at> gmail.com>

Date: Thu, 26 Feb 2015 13:30:03 UTC

Severity: normal

Tags: notabug

Done: Assaf Gordon <assafgordon <at> gmail.com>

Bug is archived. No further changes may be made.

Full log


View this message in rfc822 format

From: Eric Blake <eblake <at> redhat.com>
To: George Shuklin <george.shuklin <at> gmail.com>, 19953 <at> debbugs.gnu.org
Subject: bug#19953: egrep: 'Invalid range end' - bug or not?
Date: Thu, 26 Feb 2015 08:06:02 -0700
[Message part 1 (text/plain, inline)]
On 02/26/2015 06:28 AM, George Shuklin wrote:
> $ echo 'sample-text'|egrep '[0-9\-a-z]'
> grep: Invalid range end

There are different regex flavors.  Some, like perl, allow you to write
[...\-...] to include a literal '-' in the middle of a larger set of
characters.  But others, like the POSIX BRE (basic) and ERE (extended)
flavors do not.  In these flavors, the ONLY way to include literal '-'
in a character set is to put it at the front or at the back of the set
being enumerated.  Any appearance of '\' in the set is taken literally;
there is no way to use '\' as an escape character.

Thus, your attempt here is requesting the set consisting of the range
from '0' to '9', from '\' to 'a', and then an unexpected '-' character
that is not the end.  It is invalid per POSIX.

> 
> but:
> 
> $ echo 'sample-text'|egrep '[0-9a-z\-]'

This requests the set from '0' to '0', the set from 'a' to 'z', the
literal '\', and the literal '-'.

As Bernhard pointed out, this is not a coreutils bug.  But it is also
not a grep bug.  It is your usage that is at fault.

-- 
Eric Blake   eblake redhat com    +1-919-301-3266
Libvirt virtualization library http://libvirt.org

[signature.asc (application/pgp-signature, attachment)]

This bug report was last modified 6 years and 214 days ago.

Previous Next


GNU bug tracking system
Copyright (C) 1999 Darren O. Benham, 1997,2003 nCipher Corporation Ltd, 1994-97 Ian Jackson.