Subject: Re: bug#15410: [:alnum:] is not [:alpha:] AND [:digit:]... [:alnum:] is [:alpha:] OR [:digit:]
From: Eric Blake <[email-masked]>
To: Nick Aganan <[email-masked]>
Cc: [email-masked]
Date: Wed, 18 Sep 2013 12:31:11 -0600
List-Id: <debbugs-submit.debbugs.gnu.org>

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