emacs-bug-tracker
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[debbugs-tracker] bug#26005: closed (bug in grep)


From: GNU bug Tracking System
Subject: [debbugs-tracker] bug#26005: closed (bug in grep)
Date: Mon, 06 Mar 2017 22:45:02 +0000

Your message dated Mon, 6 Mar 2017 16:44:01 -0600
with message-id <address@hidden>
and subject line Re: bug#26005: bug in grep
has caused the debbugs.gnu.org bug report #26005,
regarding bug in grep
to be marked as done.

(If you believe you have received this mail in error, please contact
address@hidden)


-- 
26005: http://debbugs.gnu.org/cgi/bugreport.cgi?bug=26005
GNU Bug Tracking System
Contact address@hidden with problems
--- Begin Message --- Subject: bug in grep Date: Mon, 6 Mar 2017 17:31:52 -0500
Hi, I tested this with latest grep 3.0 in linux RHEL and some Ubuntu servers as well.

To reproduce run in empty directory

echo "start_string_20091210.end" | grep -o [1-2][0][0-1][0-9][0-1][0-9][0-3][0-9]
mkdir 20011209
echo "start_string_20091210.end" | grep -o [1-2][0][0-1][0-9][0-1][0-9][0-3][0-9]
rmdir 20011209
echo "start_string_20091210.end" | grep -o [1-2][0][0-1][0-9][0-1][0-9][0-3][0-9]


the results is

20091210
20091210

grep return is empty when directory, 20011209, is present and is as expected when directory removed.

Thanks for reading,
Ildar




--- End Message ---
--- Begin Message --- Subject: Re: bug#26005: bug in grep Date: Mon, 6 Mar 2017 16:44:01 -0600 User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101 Thunderbird/45.7.0
tag 26005 notabug
thanks

On 03/06/2017 04:31 PM, Ildar Rakhmanov wrote:
> Hi, I tested this with latest grep 3.0 in linux RHEL and some Ubuntu
> servers as well.
> 
> To reproduce run in empty directory
> 
> echo "start_string_20091210.end" | grep -o
> [1-2][0][0-1][0-9][0-1][0-9][0-3][0-9]

Underquoted.  This asks the shell to perform globbing for all files that
match those patterns.  Initially, none do, so the shell passes the
pattern on unchanged to grep.

> mkdir 20011209

Now the glob succeeds, so you are invoking

echo ... | grep -o 20011209

which is NOT what you meant (it searches for the regex 20011209 in the
input, which is not present).

> echo "start_string_20091210.end" | grep -o
> [1-2][0][0-1][0-9][0-1][0-9][0-3][0-9]
> rmdir 20011209

For even more fun, try:

touch 20011209 20011210

now your grep will also output nothing.  Why? because you end up invoking:

echo ... | grep -o 20011209 20011210

which completely ignores stdin and searches for the string 20011209 in
the (empty) file 20011210.


If you had typed:

echo ... | grep -o '[1-2][0][0-1][0-9][0-1][0-9][0-3][0-9]'

then you would be immune from shell globbing changing the parameters
based on the contents of the current directory.

As the problem is in your improper use of shell quoting, and not in
grep, I'm closing this as not a bug. However, feel free to respond if
you still have questions.

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

Attachment: signature.asc
Description: OpenPGP digital signature


--- End Message ---

reply via email to

[Prev in Thread] Current Thread [Next in Thread]