buggrep - Bugs: bug #35668, odd behaviour with wildcard...

 
 

You are not allowed to post comments on this tracker with your current authentication level.

bug #35668: odd behaviour with wildcard patterns accidently matching file names

Submitted by:  Matthias Gorzellik <gotzl>
Submitted on:  Wed 29 Feb 2012 03:43:29 PM UTC  
 
Category: NoneSeverity: 3 - Normal
Item Group: NoneStatus: Invalid
Privacy: PublicAssigned to: None
Open/Closed: Closed

Wed 29 Feb 2012 10:51:14 PM UTC, comment #2:

Just wanted to thank you for pointing out my mistake in that length , I really appreciate that ! Sorry for filing an invalid bug, but at least I think I've learned s.t. ;)

Matthias Gorzellik <gotzl>
Wed 29 Feb 2012 04:20:10 PM UTC, comment #1:

I'm closing this; it is not a bug in grep, but in your (mis-)use of the shell.

~ $ echo -e "123\n456" > test

echo -e is not portable. POSIX recommends that you use printf(1) instead:

printf "123\n456\n" > test

~ $ cat test | grep [0-9][0-9][0-9]
123
456

Useless use of cat.

Missing shell quoting. When you have no files that match the glob, then the glob is passed through unchanged, so you are grepping for the pattern '[0-9][0-9][0-9]'.

~ $ touch 456
~ $ cat test | grep [0-9][0-9][0-9]
456

Now that the glob matches, the shell expands it to the matching file name, '456', so you are now grepping for the pattern '456'.

To see the difference, try:

echo [0-9][0-9][0-9]

both before and after creating one or more files with a 3-digit name. What you meant to do was:

grep '[0-9][0-9][0-9]' < test

Or, more compactly,

grep '[0-9]\{3\}' < test

Eric Blake <ericb>
Project Member
Wed 29 Feb 2012 03:43:29 PM UTC, original submission:

Scenario: extract numbers out of some text file

~ $ echo -e "123\n456" > test
~ $ cat test | grep [0-9][0-9][0-9]
123
456
~ $ touch 456
~ $ cat test | grep [0-9][0-9][0-9]
456

It seems that despite I pipe the output of cat to grep, it is getting confused with a file matching the patter.
Doing "cat test | grep -e[0-9][0-9][0-9]" solves the problem,
but I find it kind of unintuitive to see grep failing w/o -e...

Matthias Gorzellik <gotzl>

 

No files currently attached

 

Depends on the following items: None found

Items that depend on this one: None found

 

Carbon-Copy List
  • -unavailable- added by ericb (Posted a comment)
  • -unavailable- added by gotzl (Submitted the item)
  •  

    Do you think this task is very important?
    If so, you can click here to add your encouragement to it.
    This task has 0 encouragements so far.

    Only logged-in users can vote.

     

    Please enter the title of George Orwell's famous dystopian book (it's a date):

     

     

    Follow 2 latest changes.

    Date Changed By Updated Field Previous Value => Replaced By
    Wed 29 Feb 2012 04:20:10 PM UTCericbStatusNone=>Invalid
      Open/ClosedOpen=>Closed

    Back to the top


    Powered by Savane 3.1-cleanup1