GNU bug report logs -
#41262
Weird behavior with grep regex
Previous Next
Reported by: <loic.tregouet <at> orange.com>
Date: Thu, 14 May 2020 14:38:02 UTC
Severity: normal
Tags: notabug
Done: Paul Eggert <eggert <at> cs.ucla.edu>
Bug is archived. No further changes may be made.
To add a comment to this bug, you must first unarchive it, by sending
a message to control AT debbugs.gnu.org, with unarchive 41262 in the body.
You can then email your comments to 41262 AT debbugs.gnu.org in the normal way.
Toggle the display of automated, internal messages from the tracker.
Report forwarded
to
bug-grep <at> gnu.org
:
bug#41262
; Package
grep
.
(Thu, 14 May 2020 14:38:02 GMT)
Full text and
rfc822 format available.
Acknowledgement sent
to
<loic.tregouet <at> orange.com>
:
New bug report received and forwarded. Copy sent to
bug-grep <at> gnu.org
.
(Thu, 14 May 2020 14:38:02 GMT)
Full text and
rfc822 format available.
Message #5 received at submit <at> debbugs.gnu.org (full text, mbox):
[Message part 1 (text/plain, inline)]
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 ?
Regards
_________________________________________________________________________________________________________________________
Ce message et ses pieces jointes peuvent contenir des informations confidentielles ou privilegiees et ne doivent donc
pas etre diffuses, exploites ou copies sans autorisation. Si vous avez recu ce message par erreur, veuillez le signaler
a l'expediteur et le detruire ainsi que les pieces jointes. Les messages electroniques etant susceptibles d'alteration,
Orange decline toute responsabilite si ce message a ete altere, deforme ou falsifie. Merci.
This message and its attachments may contain confidential or privileged information that may be protected by law;
they should not be distributed, used or copied without authorisation.
If you have received this email in error, please notify the sender and delete this message and its attachments.
As emails may be altered, Orange is not liable for messages that have been modified, changed or falsified.
Thank you.
[Message part 2 (text/html, inline)]
Added tag(s) notabug.
Request was from
Eric Blake <eblake <at> redhat.com>
to
control <at> debbugs.gnu.org
.
(Thu, 14 May 2020 15:22:01 GMT)
Full text and
rfc822 format available.
Information forwarded
to
bug-grep <at> gnu.org
:
bug#41262
; Package
grep
.
(Thu, 14 May 2020 18:53:01 GMT)
Full text and
rfc822 format available.
Message #10 received at submit <at> debbugs.gnu.org (full text, mbox):
On 2020-05-14, loic.tregouet 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 ?
You are not quoting the pattern so it is being expanded by the
shell. The shell sees the argument as a pathname pattern to be
expanded. If there is no matching file name, the shell leaves the
argument unchanged and passes [a-z] to grep. If there is a matching
file name, as there is after you touch t, then the shell expands
that pattern to the matching file t and passes t to grep.
The solution is to enclose the pattern in quotes, either single or
double, like this:
$ echo a | grep "[a-z]"
or to escape one or both of the brackets, like this:
$ echo a | grep \[a-z\]
Regards,
Gary
Information forwarded
to
bug-grep <at> gnu.org
:
bug#41262
; Package
grep
.
(Thu, 14 May 2020 18:53:02 GMT)
Full text and
rfc822 format available.
Message #13 received at 41262 <at> debbugs.gnu.org (full text, mbox):
Hi Loic!
On Thu, 14 May 2020 13:57:48 +0000
<loic.tregouet <at> orange.com> 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
> $
>
This is standard Unix shell ( sh / ksh / bash ) globbing behaviour:
https://en.wikipedia.org/wiki/Glob_%28programming%29
Quoting works:
```
[shlomif <at> localhost ~]$ cd tmp
[shlomif <at> localhost tmp]$ touch t
[shlomif <at> localhost tmp]$ echo a | grep [a-z]
[shlomif <at> localhost tmp]$ echo a | grep '[a-z]'
a
[shlomif <at> localhost tmp]$ echo a | grep "[a-z]"
a
[shlomif <at> localhost tmp]$
```
Also see https://perl-begin.org/topics/security/code-markup-injection/ .
>
> Any idea ?
>
> Regards
>
> _________________________________________________________________________________________________________________________
>
> Ce message et ses pieces jointes peuvent contenir des informations
> confidentielles ou privilegiees et ne doivent donc pas etre diffuses,
> exploites ou copies sans autorisation. Si vous avez recu ce message par
> erreur, veuillez le signaler a l'expediteur et le detruire ainsi que les
> pieces jointes. Les messages electroniques etant susceptibles d'alteration,
> Orange decline toute responsabilite si ce message a ete altere, deforme ou
> falsifie. Merci.
>
> This message and its attachments may contain confidential or privileged
> information that may be protected by law; they should not be distributed,
> used or copied without authorisation. If you have received this email in
> error, please notify the sender and delete this message and its attachments.
> As emails may be altered, Orange is not liable for messages that have been
> modified, changed or falsified. Thank you.
>
Ahem :(
--
Shlomi Fish https://www.shlomifish.org/
https://www.shlomifish.org/humour/Summerschool-at-the-NSA/
Knuth is not God! Typing “God” into Google and pressing “I’m Feeling Lucky”
will not lead you to his homepage.
— https://www.shlomifish.org/humour/bits/facts/Knuth/
Please reply to list if it's a mailing list post - https://shlom.in/reply .
bug closed, send any further explanations to
41262 <at> debbugs.gnu.org and <loic.tregouet <at> orange.com>
Request was from
Paul Eggert <eggert <at> cs.ucla.edu>
to
control <at> debbugs.gnu.org
.
(Mon, 21 Sep 2020 19:31:01 GMT)
Full text and
rfc822 format available.
bug archived.
Request was from
Debbugs Internal Request <help-debbugs <at> gnu.org>
to
internal_control <at> debbugs.gnu.org
.
(Tue, 20 Oct 2020 11:24:12 GMT)
Full text and
rfc822 format available.
This bug report was last modified 3 years and 182 days ago.
Previous Next
GNU bug tracking system
Copyright (C) 1999 Darren O. Benham,
1997,2003 nCipher Corporation Ltd,
1994-97 Ian Jackson.