Subject: Re: bug#41262: Weird behavior with grep regex

From: Eric Blake <[email-masked]>
Date: Thu, 14 May 2020 10:21:07 -0500

tag 41262 notabug
thanks

On 5/14/20 8:57 AM, [email-masked] wrote:
> Hi,
> 
> I've reproduced a strange behaviour of grep command when a file name of a single letter is present in current directory .
> 
> $ echo a | grep [a-z]
> a
> $ touch t
> $ echo a | grep [a-z]
> $ rm t
> $ echo a | grep [a-z]
> a
> $
> 
> 
> Any idea ?

Improper quoting.  Notice:

$ rm -f ?
$ echo [a-z]
[a-z]
$ echo "[a-z]"
[a-z]
$ touch t
$ echo [a-z]
t
$ echo "[a-z]"
[a-z]

your shell is globbing [a-z] when there is a filename for it to match. 
The globbing happens prior to the execution of grep, so it is not grep's 
fault ('echo a | grep t' correctly outputs no match), therefore I'm 
closing this as not a bug.  But feel free to reply if you have further 
questions on the topic.

> Ce message et ses pieces jointes peuvent contenir des informations confidentielles ou privilegiees et ne doivent donc

Disclaimers like this are unenforceable on publicly-archived lists, and 
don't add anything useful to the conversation.  It may be nicer to send 
mails from a personal account that does not slam us with your employer's 
legalese.

-- 
Eric Blake, Principal Software Engineer
Red Hat, Inc.           +1-919-301-3226
Virtualization:  qemu.org | libvirt.org