GNU bug report logs - #15410
[:alnum:] is not [:alpha:] AND [:digit:]... [:alnum:] is [:alpha:] OR [:digit:]

Previous Next

Package: grep;

Reported by: Nick Aganan <thesysad <at> gmail.com>

Date: Wed, 18 Sep 2013 16:13:02 UTC

Severity: normal

Tags: notabug

Done: Eric Blake <eblake <at> redhat.com>

Bug is archived. No further changes may be made.

Full log


View this message in rfc822 format

From: help-debbugs <at> gnu.org (GNU bug Tracking System)
To: Eric Blake <eblake <at> redhat.com>
Cc: tracker <at> debbugs.gnu.org
Subject: bug#15410: closed ([:alnum:] is not [:alpha:] AND [:digit:]...
 [:alnum:] is [:alpha:] OR [:digit:])
Date: Wed, 18 Sep 2013 18:32:03 +0000
[Message part 1 (text/plain, inline)]
Your message dated Wed, 18 Sep 2013 12:31:11 -0600
with message-id <5239F16F.8050204 <at> redhat.com>
and subject line Re: bug#15410: [:alnum:] is not [:alpha:] AND [:digit:]... [:alnum:] is [:alpha:] OR [:digit:]
has caused the debbugs.gnu.org bug report #15410,
regarding [:alnum:] is not [:alpha:] AND [:digit:]... [:alnum:] is [:alpha:] OR [:digit:]
to be marked as done.

(If you believe you have received this mail in error, please contact
help-debbugs <at> gnu.org.)


-- 
15410: http://debbugs.gnu.org/cgi/bugreport.cgi?bug=15410
GNU Bug Tracking System
Contact help-debbugs <at> gnu.org with problems
[Message part 2 (message/rfc822, inline)]
From: Nick Aganan <thesysad <at> gmail.com>
To: bug-grep <at> gnu.org
Subject: [:alnum:] is not [:alpha:] AND [:digit:]... [:alnum:] is [:alpha:] OR
 [:digit:]
Date: Wed, 18 Sep 2013 12:07:00 -0400
[Message part 3 (text/plain, inline)]
[:alnum:] is defined as

Alphanumeric characters: ‘[:alpha:]’ *and* ‘[:digit:]’; in the ‘C’ locale
and ASCII character encoding, this is the same as ‘[0-9A-Za-z]’.



AND = need to satisfy *BOTH* alpha and digit

OR = need to satisfy *EITHER* alpha or digit





It looks like ‘[:alpha:]’ *AND* ‘[:digit:]’ functions as ‘[:alpha:]’ *OR* ‘
[:digit:]’, See example





Example:

# cat /tmp/c

adc

x1y1z123

456



# grep [[:alpha:]] /tmp/c

adc

x1y1z123



# grep [[:digit:]] /tmp/c

x1y1z123

456



# grep [[:alnum:]] /tmp/c

adc

x1y1z123

456





### if [:alnum] functions as ‘[:alpha:]’ *AND* ‘[:digit:]’, it should show
x1y1z123 only
[Message part 4 (text/html, inline)]
[Message part 5 (message/rfc822, inline)]
From: Eric Blake <eblake <at> redhat.com>
To: Nick Aganan <thesysad <at> gmail.com>
Cc: 15410-done <at> debbugs.gnu.org
Subject: Re: bug#15410: [:alnum:] is not [:alpha:] AND [:digit:]... [:alnum:]
 is [:alpha:] OR [:digit:]
Date: Wed, 18 Sep 2013 12:31:11 -0600
[Message part 6 (text/plain, inline)]
tag 15410 notabug
thanks

On 09/18/2013 10:07 AM, Nick Aganan wrote:
> [:alnum:] is defined as
> 
> Alphanumeric characters: ‘[:alpha:]’ *and* ‘[:digit:]’; in the ‘C’ locale
> and ASCII character encoding, this is the same as ‘[0-9A-Za-z]’.

This sense of "and" correctly means the combination, where characters
from either class satisfy the regex.  Writing '[[:alnum:]]' is the same
as writing '[[:alpha:][:digit:]]'


> Example:
> 
> # cat /tmp/c
> 
> adc
> 
> x1y1z123
> 
> 456

[Your mailer is rather unconventional, and sticks lots of useless
whitespace into your content]

> 
> 
> 
> # grep [[:alpha:]] /tmp/c
> 
> adc
> 
> x1y1z123

Whoops - you didn't quote your shell argument.  I suspect you have some
single-character file names in your current directory (further bolstered
by the fact that you named your file /tmp/c, although it is not obvious
whether your current working directory is /tmp or elsewhere).
Therefore, you are falling victim to shell globbing.

Remember, if a file named 'a' exists in the current directory, then
unquoted [] expressions perform globs that might be replaced by that
file name:

$ touch a
$ echo '[[:alpha:]]' [[:alpha:]]
[[:alpha:]] a

You are NOT grepping for the char class "[[:alpha:]]", but for the
entirely different regex that matches the unfortunate file name
expansion of your glob.  Use shell quotes properly, and you will then
see the desired answers.  Or prepend 'echo' to your grep command to see
what arguments were actually being handed to grep.

Given that the problem is in your lack of shell quoting, and not in
grep, I'm closing this as not a bug.  However, feel free to respond if
you have more comments.

-- 
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 11 years and 305 days ago.

Previous Next


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