bug-grep
[Top][All Lists]
Advanced

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

Re: TTY-dependent GREP_OPTIONS


From: Jim Meyering
Subject: Re: TTY-dependent GREP_OPTIONS
Date: Sun, 08 Jul 2012 19:21:02 +0200

Julius Werner wrote:
> I'm a big fan of GREP_OPTIONS - I usually use "--color=auto -n -r
> --exclude=*.svn-base" because it saves so much hassle in everyday
> use. However, as most of you are probably aware, this (especially -n)
> can seriously break scripts and makefiles that often don't expect it.
>
> Have you ever considered changing the behavior of GREP_OPTIONS to only
> apply when the output is a terminal (similar to --color=auto)? I think
> this would reliably solve the problem and I can't think of a use case
> where one would actually want GREP_OPTIONS to apply to non-terminal
> outputs.

If I were to implement a compatibility-breaking change,
it would be to remove support for GREP_OPTIONS altogether.
IMHO, introducing that option was a mistake for precisely
the reason you mention: with it, any robust grep-using script
must now unset or clear GREP_OPTIONS.

> Alternatively, if you don't want to break backwards-compatibility, how
> about adding a new variable for this behavior? It's such a great
> convenience feature, but hardly useable in its current form because so
> many scripts rely on a unmodified grep.

I suggest you use a shell function instead:

  grep() { env grep --color=auto -nr --exclude='*.svn-base' "$@"; }



reply via email to

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