[Top][All Lists]

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

bug#17494: grep bug report: "GREP_OPTIONS" allows a user to break shell

From: Nadav Har'El
Subject: bug#17494: grep bug report: "GREP_OPTIONS" allows a user to break shell script
Date: Thu, 15 May 2014 10:18:14 +0300

On Thu, May 15, 2014 at 8:08 AM, Paul Eggert <address@hidden> wrote:

> Nadav Har'El wrote:
>> So I think it would be best if you drop the GREP_OPTIONS feature
>> completely.
> I tend to agree.  Hindsight is wonderful of course, but GREP_OPTIONS
> should never have been added, as it's a real minefield.

Yes, as they say, hindsight is always 20/20 ;-)

>  But how would we minimize breakage of existing usage that relies on
> GREP_OPTIONS?  If we removed it, we'd probably need a transition period,
> and have documentation of how to get the old behavior if you want it, etc.

I think deprecating and un-recommending this option in the manual page will
be a good start (and I just now noticed that
https://savannah.gnu.org/bugs/?32501 asked for the same thing). I think
that the only reason people use this variable is that they read through the
manual page, and thought it would be cool to set it to something like
"--with-color -n". So the manual page should be clear that it's not cool to
use it, and what the alternative is.

I don't mind that people use such an option if they are well aware of what
they are doing, and if they are aware that it is their environment which is
broken, not the shell scripts they use, and don't expect every shell script
which uses grep to begin with "unset GREP_OPTIONS".

Here is a patch I propose to the grep(1) manual page:

diff --git a/grep.1.orig b/grep.1
index fb99665..9d2a8d3 100644
--- a/grep.1.orig
+++ b/grep.1
@@ -875,6 +875,21 @@ had been specified before any explicit options.
 Option specifications are separated by whitespace.
 A backslash escapes the next character,
 so it can be used to specify an option containing whitespace or a
+This variable is deprecated, and should be avoided. Setting it changes not
+only the behavior of
+.B grep
+in interactive shell sessions, but may also break shell scripts and
+which assume that
+.B grep
+behaves normally. A user that wishes to alter the default
+.B grep
+behavior only for interactive sessions should instead use the
+.I alias
+feature provided by the shell, e.g.,
+alias grep='grep --color=auto -n'
 This variable specifies the color used to highlight matched (non-empty)

Nadav Har'El

reply via email to

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