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

Submitter:  None
Submitted:  Sun 28 Dec 2008 09:21:49 PM UTC
Votes: 110
 
Category:  None Severity:  3 - Normal
Item Group:  None Status:  None
Privacy:  Public Assigned 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
-email is unavailable-

Anonymous

 

(Note: upload size limit is set to 16384 kB, after insertion of the required escape characters.)

No files currently attached

 

Depends on the following items: None found

Items that depend on this one: None found

 

Carbon-Copy List
  • -email is unavailable- added by bonzini (Posted a comment)
  • -email is unavailable- added by divanorama (Voted in favor of this item)
  • -email is unavailable- added by nicalvaro (Posted a comment)
  • -email is unavailable- added by ebroder (Voted in favor of this item)
  • -email is unavailable- added by geofft (Posted a comment)
  • -email is unavailable- added by geofft
  •  

    There are 110 votes so far. Votes easily highlight which items people would like to see resolved in priority, independently of the priority of the item set by tracker managers.

     

    Follow 4 latest changes.

    Date Changed by Updated Field Previous Value => Replaced by
    2009-12-04 bonzini Open/ClosedOpen Closed
    2009-07-31 divanorama Carbon-Copy- Added divanorama
    2008-12-28 ebroder Carbon-Copy- Added ebroder
    2008-12-28 geofft Carbon-Copy- Added geofft

    Back to the top

    Powered by Savane 3.13-758e.
    Corresponding source code