patchgrep - Patches: patch #6474, Issue warning if recursively...

 
 

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

patch #6474: Issue warning if recursively searching stdin

Submitter:  Rainer Müller <raimue>
Submitted:  Sun 23 Mar 2008 04:11:55 AM UTC
   
 
Category:  None Priority:  5 - Normal
Status:  None Privacy:  Public
Assigned to:  None Open/Closed:  Open

Jump to the original submission

Tue 20 Mar 2012 08:21:26 PM UTC, comment #7: 

By jove that works a treat. Thanks for teaching me something. My objection to this patch is retracted.

Jonathan Hartley <tartley>
Tue 20 Mar 2012 08:03:55 PM UTC, comment #6: 

No.  You want to expand:

$ grp XXX

into

$ GREP_OPTIONS=-r grep --exclude-dir...

Notice that this is a one-shot environment modification, for just the grep process.  Don't believe me?  Try this:

$ export foo=bar
$ env | grep ^foo
$ foo=blah env | grep ^foo
$ env | grep ^foo

and notice how setting an env-var immediately before the command name is a one-shot modification of the environment seen by just that command.

You may also want to note that the bash manual recommends shell functions rather than aliases, as in:

grp() {
  GREP_OPTIONS=-r grep --exclude-dir=... "$@"
}

Eric Blake <ericb>
Group Member
Tue 20 Mar 2012 08:03:45 PM UTC, comment #5: 

Interesting idea, thanks Eric. Unfortunately, my bash-fu is not sufficient to fill in the ellipsis. My understanding is that the alias would have to be such that it expands the command-line:

$ grp XXX

into

GREP_OPTIONS='--exclude-dir ...'; grep XXX; unset GREP_OPTIONS'

Is this remotely right? How do I get 'XXX' (what I typed on the command line after my alias) to appear in the middle of the alias expansion, rather than at the end of it? Or should I be invoking grep in a new shell somehow?

Also, I don't yet understand how this would work when piping data in. My attempt above fails to send piped data to the 'grep' command.

The answer 'go read man bash' is not entirely inappropriate, if you are fairly sure it can be done.

Jonathan Hartley <tartley>
Tue 20 Mar 2012 07:54:29 PM UTC, comment #4: 

Interesting idea, thanks Eric. Unfortunately, my bash-fu is not sufficient to fill in the ellipsis. My understanding is that the alias would have to be such that it expands the command-line:

$ grp XXX

into

GREP_OPTIONS='--exclude-dir ...'; grep XXX; unset GREP_OPTIONS'

Is this remotely right? How do I get 'XXX' (what I typed on the command line after my alias) to appear in the middle of the alias, rather than after it?

The answer 'go read man bash' is not entirely unappropriate, if you are fairly sure it can be done.

Jonathan Hartley <tartley>
Tue 20 Mar 2012 07:40:54 PM UTC, comment #3: 

What's wrong with having your alias temporarily set GREP_OPTIONS for just the duration of the use of your alias?  That is, instead of:

alias grp 'grep -r -l ...'

use

alias grp 'GREP_OPTIONS=-r grep -l ...'

Eric Blake <ericb>
Group Member
Tue 20 Mar 2012 07:37:16 PM UTC, comment #2: 

This patch has a minor downside. It's not uncommon to invoke 'grep' using an alias or wrapper script, in order to set some commonly-used options. For example, my own alias looks like:

alias grp='grep -rI --color --exclude-dir=\.bzr --exclude-dir=\.git --exclude-dir=\.hg --exclude-dir=\.svn --exclude-dir=build --exclude-dir=dist --exclude=tags'

Notice that I like to include '-r' in my alias, so all my invocations of 'grep', whether searching files or filtering stdin, will include '-r'.

Previously this was harmless and silent. But if I understand this patch correctly, this will now output a warning every time, which I don't like.

Obviously there are workarounds, such as removing '-r' from my alias, and typing it when I want it, or creating two aliases, one with '-r' and one without. But personally, I'd prefer if no warning was issued.

Incidentally, I don't think I can use 'GREP_OPTIONS' instead of an alias, because that breaks tools which invoke grep internally.

Jonathan Hartley <tartley>
Sun 23 Mar 2008 04:11:55 AM UTC, comment #1: 

This item has been reassigned from the project grep bugs tracker to your tracker.

The original report is still available at bugs #22375

Following are the information included in the original report:

[field #0]                  Item ID: 22375
[field #1]                 Group ID: 67
[field #2]              Open/Closed: Open
[field #3]                 Severity: 3 - Normal
[field #4]                  Privacy: Public
[field #6]                    Votes: 10
[field #8]                         : Unknown bugs Field Display Type
[field #9]                 Category: None
[field #10]             Submitted by: raimue
[field #11]              Assigned to: None
[field #12]             Submitted on: Thursday 02/21/2008 at 10:27
[field #13]                  Summary: Issue warning if recursively searching stdin
[field #14]      Original Submission: This is a patch by Apple, which can be retrieved from their patches subdirectory of their source release [1]. Also attached it here for convenience.

[1] http://www.opensource.apple.com/darwinsource/Current/grep-24/patches/PR-4053512.diff


[field #16]               Item Group: None
[field #17]                   Status: None
[field #18]        Component Version: None
[field #19]         Operating System: None
[field #20]          Reproducibility: None
[field #21]               Size (loc): None
[field #22]            Fixed Release: None
[field #23]          Planned Release: None
[field #24]                   Effort: 0.00
[field #28]                 Priority: 5 - Normal
[field #31]         Percent Complete: 0%
[field #33]                  Release: None
[field #58]     Custom Select Box #1: None
[field #59]     Custom Select Box #2: None
[field #60]     Custom Select Box #3: None
[field #61]     Custom Select Box #4: None
[field #62]     Custom Select Box #5: None
[field #63]     Custom Select Box #6: None
[field #64]     Custom Select Box #7: None
[field #65]     Custom Select Box #8: None
[field #66]     Custom Select Box #9: None
[field #67]    Custom Select Box #10: None

Tony Abou-Assaleh <taa>
Group administrator
Sun 23 Mar 2008 04:11:55 AM UTC, original submission:  

This is a patch by Apple, which can be retrieved from their patches subdirectory of their source release [1]. Also attached it here for convenience.

[1] http://www.opensource.apple.com/darwinsource/Current/grep-24/patches/PR-4053512.diff


Rainer Müller <raimue>

 

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

Attached Files
file #15090:  PR-4053512.diff added by raimue (495B - text/x-diff)

 

Depends on the following items: None found

Items that depend on this one: None found

 

Carbon-Copy List
  • -email is unavailable- added by ericb (Posted a comment)
  • -email is unavailable- added by tartley (Posted a comment)
  • -email is unavailable- added by raimue (Submitted the item)
  • -email is unavailable- added by raimue
  •  

    There are 0 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.

     

    Follows 1 latest change.

    Date Changed by Updated Field Previous Value => Replaced by
    2008-03-23 taa Reassign itemgrep, bug #22375 grep, patch #6474

    Back to the top

    Powered by Savane 3.13-f8d8.
    Corresponding source code