buggrep - Bugs: bug #25197, grep -R defaults to stdin, not the...

 
 

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

bug #25197: grep -R defaults to stdin, not the current directory

Submitted by:  None
Submitted on:  Sun 28 Dec 2008 09:21:49 PM UTC  
Votes:  110  
 
Category: NoneSeverity: 3 - Normal
Item Group: NoneStatus: None
Privacy: PublicAssigned to: None
Open/Closed: Closed

Fri 04 Dec 2009 11:28:39 PM UTC, comment #5:

Sorry for being a bit too terse. The main reason why this cannot be changed is interoperability. Even though POSIX does not include -r, other grep implementations such as NetBSD grep do, and it would be bad to break compatibility with it (as well as with scripts written in the past ~20 years). I do see the point in your proposal, but it's not really feasible to go beyond warning.

> As another example, note that the git project's 'git grep'
> defaults to the current directory without a '.' argument.


This is different; git grep does not have a non-recursive mode (AFAICT) and cannot ever get its input from stdin.

Paolo Bonzini <bonzini>
Fri 04 Dec 2009 10:58:37 PM UTC, comment #4:

Hi Paolo,

Just to clarify, the bug here is that grep -R should default to the current directory if none is specified.

I'm okay with Apple's patch to warn but not change behavior as a compromise if this behavior is somehow undesirable, but I don't see why it would be, and I would expect lots of grep users to want this behavior -- there are multiple people who found this ticket and voted in favor of it, for instance.

As another example, note that the git project's 'git grep' defaults to the current directory without a '.' argument. I would imagine that Apple simply didn't want to diverge so much from upstream, and took the conservative approach.

Recursive grep of something that is not a directory (e.g., stdin) is meaningless, so stdin is not a reasonable default for grep -R.

- Geoffrey

Geoffrey Thomas <geofft>
Fri 04 Dec 2009 01:00:38 PM UTC, comment #3:

Not a bug, there is an open ticket about adding the warning.

Paolo Bonzini <bonzini>
Sat 14 Feb 2009 03:30:45 AM UTC, comment #2:

The work around I use is either being above the directory to scan or placing a ./ at the end of the command.

grep -r HI ./

To me it would be very reasonable to not have to place an argument at the end of the command for a recursive grep of the current directory as the './' is not very neat.

-Deleted Account- <nicalvaro>
Sun 28 Dec 2008 09:46:28 PM UTC, comment #1:

Apple's patch to print a warning but continue with stdin appears to be
http://www.opensource.apple.com/darwinsource/10.5.6/grep-24/patches/PR-4053512.diff

See https://savannah.gnu.org/patch/?6473 for a request to incorporate Apple's patches, but I would be fine with reimplementing this differently, e.g., by defaulting to the current directory.

Geoffrey Thomas <geofft>
Sun 28 Dec 2008 09:21:49 PM UTC, original submission:

When I type "grep -R pattern", I never want to search stdin, because it's meaningless to search stdin recursively. I usually meant to do "grep -R pattern .". grep -R should default to searching the current directory, or at least give an error message and quit, instead of hanging waiting for input.

The problem with hanging waiting for input is that you might think that it's taking a few seconds or even a few minutes to search a large directory and not realize your error until a good while later.

I hear that GNU grep as patched by Apple in Mac OS X gives a warning in this circumstance, which would be sufficient.

--
Geoffrey Thomas
-unavailable-

Anonymous

 

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 bonzini (Posted a comment)
  • -unavailable- added by divanorama (Voted in favor of this item)
  • -unavailable- added by nicalvaro (Posted a comment)
  • -unavailable- added by ebroder (Voted in favor of this item)
  • -unavailable- added by geofft (Posted a comment)
  • -unavailable- added by geofft
  •  

    Do you think this task is very important?
    If so, you can click here to add your encouragement to it.
    This task has 110 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 4 latest changes.

    Date Changed By Updated Field Previous Value => Replaced By
    Fri 04 Dec 2009 01:00:38 PM UTCbonziniOpen/ClosedOpen=>Closed
    Fri 31 Jul 2009 12:24:26 PM UTCdivanoramaCarbon-Copy-=>Added divanorama
    Sun 28 Dec 2008 10:07:38 PM UTCebroderCarbon-Copy-=>Added ebroder
    Sun 28 Dec 2008 09:43:13 PM UTCgeofftCarbon-Copy-=>Added geofft

    Back to the top


    Powered by Savane 3.1-cleanup1