From unknown Sat Aug 16 16:23:27 2025 X-Loop: help-debbugs@gnu.org Subject: bug#17494: grep bug report: "GREP_OPTIONS" allows a user to break shell script Resent-From: "Nadav Har'El" Original-Sender: "Debbugs-submit" Resent-CC: bug-grep@gnu.org Resent-Date: Wed, 14 May 2014 22:21:01 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: report 17494 X-GNU-PR-Package: grep X-GNU-PR-Keywords: To: 17494@debbugs.gnu.org Cc: Osv Dev X-Debbugs-Original-To: bug-grep@gnu.org Received: via spool by submit@debbugs.gnu.org id=B.140010601531395 (code B ref -1); Wed, 14 May 2014 22:21:01 +0000 Received: (at submit) by debbugs.gnu.org; 14 May 2014 22:20:15 +0000 Received: from localhost ([127.0.0.1]:34958 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.80) (envelope-from ) id 1WkhX3-0008AG-Je for submit@debbugs.gnu.org; Wed, 14 May 2014 18:20:14 -0400 Received: from eggs.gnu.org ([208.118.235.92]:39228) by debbugs.gnu.org with esmtp (Exim 4.80) (envelope-from ) id 1WkhFC-0007bp-3w for submit@debbugs.gnu.org; Wed, 14 May 2014 18:01:46 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1WkhF1-0008A9-Pz for submit@debbugs.gnu.org; Wed, 14 May 2014 18:01:41 -0400 X-Spam-Checker-Version: SpamAssassin 3.3.2 (2011-06-06) on eggs.gnu.org X-Spam-Level: X-Spam-Status: No, score=0.8 required=5.0 tests=BAYES_50,HTML_MESSAGE autolearn=disabled version=3.3.2 Received: from lists.gnu.org ([2001:4830:134:3::11]:33142) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1WkhF1-0008A5-Nc for submit@debbugs.gnu.org; Wed, 14 May 2014 18:01:35 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:40905) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1WkhEw-00047b-W9 for bug-grep@gnu.org; Wed, 14 May 2014 18:01:35 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1WkhEs-0007wB-8Z for bug-grep@gnu.org; Wed, 14 May 2014 18:01:30 -0400 Received: from mail-pa0-f54.google.com ([209.85.220.54]:43064) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1WkhEs-0007uy-0W for bug-grep@gnu.org; Wed, 14 May 2014 18:01:26 -0400 Received: by mail-pa0-f54.google.com with SMTP id bj1so153255pad.27 for ; Wed, 14 May 2014 15:01:24 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:date:message-id:subject:from:to:cc :content-type; bh=iN5aN0hQ0GgLtLYSTvn7YOxICnFCeGNkaFLQX5C4V24=; b=aEq3wUhWXDL8bIK0r02mtAL8orkIGarXN5pwVnVy9rJMnuZ8J5nd5V6EOjgZFRL7Sm KndFpbqv1lxX6jMkyjAVXZklfqWCXkxCwdrNAyE/SsH27bR9/yiyZM7aogdL9e97L65Z gjFHvoA2CY2CbnqWi82VzWeKPfyea/AL01t2+kTOGxpy+mrVS2bJcdsQwk3L6vOzyxf2 SdA/tvFTKxQA82mzzF2cRv6E1FtBOo/zCIb1Danyq1o5KuJUASyB+i0xe85OKG9RFBcD GEFzcHJLX7FojDpCpztZdDmQBt6i8aUyLbK6yniklbbn59GYivhD7djZTl5Utr6iI1MR PQXg== X-Gm-Message-State: ALoCoQnDs46W/S+0V9yVBgRLKr/sIbzCTy9PFiuJ+bip1CmBMiC6S0vGS/H2DWfAR7zScJGuz3tM MIME-Version: 1.0 X-Received: by 10.68.193.100 with SMTP id hn4mr7635240pbc.50.1400104884441; Wed, 14 May 2014 15:01:24 -0700 (PDT) Received: by 10.66.159.68 with HTTP; Wed, 14 May 2014 15:01:24 -0700 (PDT) Date: Thu, 15 May 2014 01:01:24 +0300 Message-ID: From: "Nadav Har'El" Content-Type: multipart/alternative; boundary=047d7bd6aa9c492bb304f963526b X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-detected-operating-system: by eggs.gnu.org: Error: Malformed IPv6 address (bad octet value). X-Received-From: 2001:4830:134:3::11 X-Spam-Score: -4.3 (----) X-Mailman-Approved-At: Wed, 14 May 2014 18:20:11 -0400 X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -4.3 (----) --047d7bd6aa9c492bb304f963526b Content-Type: text/plain; charset=UTF-8 Hi, An unsuspecting user who reads the grep(1) manual page and discovers the GREP_OPTIONS environment variable, might thing it is a cool idea to set it. For example, set GREP_OPTIONS=-n to always get numbers on the output, great isn't it? Well, it's actually a really bad idea to export GREP_OPTIONS=-n, or anything similar, because this will effect not only the user's interactive work in his shell, but also likely break any shell-script, makefile, and so on, which happens to use "grep" and assume that it behaves normally. Imagine what kind a mess a user could cause by setting GREP_OPTIONS=-v :-) Instead of setting GREP_OPTIONS hoping it will only effect his interactive session, what the user should have done is to use an *alias*, e.g., alias grep='grep -n' In fact on my Fedora installation, there is already a similar alias by default: alias grep='grep --color=auto' These aliases (when put in .bashrc or similar) are safe - they only effect the user's interactive shell, and *not* shell scripts or makefiles, which use the normal grep as they expect. So I think it would be best if you drop the GREP_OPTIONS feature completely. Or if for some reason you really don't want to drop it, please at least explain in the manual page why it is dangerous and aliases should be preferred. An example of the kind of damage the availability of this option can do is that today, a user of an open-source project I'm working on (OSv), asked us to replace every use of "grep" in our makefile to calls to "GREP_OPTIONS= grep", so that grep will continue to work normally even for people who set GREP_OPTIONS. A final remark: Other command-line utilities, such as "ls", "rm", "cat" and so on, also don't have a .._OPTIONS variable of the sort grep has. Imagine what kind of havoc users could cause to shell scripts if they could do RM_OPTIONS=-i. Instead, what users have been doing for many years is to alias ls, rm, and so on. They can change "rm" to "rm -i" for themselves, but it won't mess with non-interactive shell-scripts. There is no reason, I think, why grep needs to be any different. Thanks, Nadav. -- Nadav Har'El nyh@cloudius-systems.com --047d7bd6aa9c492bb304f963526b Content-Type: text/html; charset=UTF-8 Content-Transfer-Encoding: quoted-printable
Hi,

An unsuspecting user who r= eads the grep(1) manual page and discovers
the GREP_OPTIONS enviro= nment variable, might thing it is a cool idea to
set it. For example, se= t GREP_OPTIONS=3D-n to always get numbers on the
output, great isn't it?

Well, it's actually a really bad ide= a to export GREP_OPTIONS=3D-n, or anything
similar, because this will ef= fect not only the user's interactive work in his shell,
but also lik= ely break any shell-script, makefile, and so on, which happens to
use "grep" and assume that it behaves normally. Imagine what kind= a mess
a user could cause by setting GREP_OPTIONS=3D-v :-)

Instead of setting GREP_OPTIONS hoping it will only effect his intera= ctive
session, what the user should have done is to use an *alias*, e.g.,

=
=C2=A0=C2=A0=C2=A0 alias grep=3D'grep -n'

In fact= on my Fedora installation, there is already a similar alias by default:

=C2=A0=C2=A0=C2=A0 alias grep=3D'grep --color=3Dauto'
These aliases (when put in .bashrc or similar) are safe - t= hey only effect
the user's interactive shell, and *not* s= hell scripts or makefiles, which
use the normal grep as they expect.

So I think it would b= e best if you drop the GREP_OPTIONS feature
completely. Or if= for some reason you really don't want to drop it,
please at least e= xplain in the manual page why it is dangerous
and aliases should be preferred.

An example of the kind of dam= age the availability of this option can do
is that today, a user of= an open-source project I'm working on (OSv),
asked us to= replace every use of "grep" in our makefile to calls to
"GREP_OPTIONS=3D grep", so that grep will continue to = work normally
even for people who set GREP_OPTIONS.

A final = remark: Other command-line utilities, such as "ls", "rm"= ;, "cat"
and so on, also don't have a .._OPTIONS variable of the sort grep has.<= br>Imagine what kind of havoc users could cause to shell scripts if theycould do RM_OPTIONS=3D-i. Instead, what users have been doing for
many = years is to alias ls, rm, and so on. They can change "rm" to &quo= t;rm -i"
for themselves, but it won't mess with non-interactive shell-scripts.
There is no reason, I think, why grep needs to be any differen= t.

Thanks,
Nadav.

--
Nadav Har'El
<= a href=3D"mailto:nyh@cloudius-systems.com" target=3D"_blank">nyh@cloudius-s= ystems.com
--047d7bd6aa9c492bb304f963526b-- From unknown Sat Aug 16 16:23:27 2025 X-Loop: help-debbugs@gnu.org Subject: bug#17494: grep bug report: "GREP_OPTIONS" allows a user to break shell script Resent-From: Paul Eggert Original-Sender: "Debbugs-submit" Resent-CC: bug-grep@gnu.org Resent-Date: Thu, 15 May 2014 05:09:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 17494 X-GNU-PR-Package: grep X-GNU-PR-Keywords: To: Nadav Har'El , 17494@debbugs.gnu.org Cc: Osv Dev Received: via spool by 17494-submit@debbugs.gnu.org id=B17494.140013051016069 (code B ref 17494); Thu, 15 May 2014 05:09:02 +0000 Received: (at 17494) by debbugs.gnu.org; 15 May 2014 05:08:30 +0000 Received: from localhost ([127.0.0.1]:35110 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.80) (envelope-from ) id 1Wknu9-0004B0-9z for submit@debbugs.gnu.org; Thu, 15 May 2014 01:08:29 -0400 Received: from smtp.cs.ucla.edu ([131.179.128.62]:49697) by debbugs.gnu.org with esmtp (Exim 4.80) (envelope-from ) id 1Wknu6-0004Ag-Gn for 17494@debbugs.gnu.org; Thu, 15 May 2014 01:08:27 -0400 Received: from localhost (localhost.localdomain [127.0.0.1]) by smtp.cs.ucla.edu (Postfix) with ESMTP id 3832DA60049; Wed, 14 May 2014 22:08:19 -0700 (PDT) X-Virus-Scanned: amavisd-new at smtp.cs.ucla.edu Received: from smtp.cs.ucla.edu ([127.0.0.1]) by localhost (smtp.cs.ucla.edu [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id vVSwPUDfUYV6; Wed, 14 May 2014 22:08:10 -0700 (PDT) Received: from [192.168.1.9] (pool-108-0-233-62.lsanca.fios.verizon.net [108.0.233.62]) by smtp.cs.ucla.edu (Postfix) with ESMTPSA id 62F08A6003B; Wed, 14 May 2014 22:08:10 -0700 (PDT) Message-ID: <53744BB5.1090008@cs.ucla.edu> Date: Wed, 14 May 2014 22:08:05 -0700 From: Paul Eggert Organization: UCLA Computer Science Department User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:24.0) Gecko/20100101 Thunderbird/24.5.0 MIME-Version: 1.0 References: In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Spam-Score: -3.0 (---) X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -3.0 (---) 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. 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. From unknown Sat Aug 16 16:23:27 2025 X-Loop: help-debbugs@gnu.org Subject: bug#17494: grep bug report: "GREP_OPTIONS" allows a user to break shell script Resent-From: "Nadav Har'El" Original-Sender: "Debbugs-submit" Resent-CC: bug-grep@gnu.org Resent-Date: Thu, 15 May 2014 07:19:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 17494 X-GNU-PR-Package: grep X-GNU-PR-Keywords: To: Paul Eggert Cc: 17494@debbugs.gnu.org, Osv Dev Received: via spool by 17494-submit@debbugs.gnu.org id=B17494.140013830531415 (code B ref 17494); Thu, 15 May 2014 07:19:02 +0000 Received: (at 17494) by debbugs.gnu.org; 15 May 2014 07:18:25 +0000 Received: from localhost ([127.0.0.1]:35154 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.80) (envelope-from ) id 1Wkpvs-0008Ab-56 for submit@debbugs.gnu.org; Thu, 15 May 2014 03:18:24 -0400 Received: from mail-pb0-f42.google.com ([209.85.160.42]:39674) by debbugs.gnu.org with esmtp (Exim 4.80) (envelope-from ) id 1Wkpvo-0008AK-J7 for 17494@debbugs.gnu.org; Thu, 15 May 2014 03:18:21 -0400 Received: by mail-pb0-f42.google.com with SMTP id md12so735315pbc.1 for <17494@debbugs.gnu.org>; Thu, 15 May 2014 00:18:14 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:in-reply-to:references:date :message-id:subject:from:to:cc:content-type; bh=6otS1740/CUkcN43HZoADEJuIZfRZy0QbO+OVCwwT08=; b=dyKszCQKpkQv6hMwtOl+YW9sKzeUmdgDe84hnt8FPcQ//dJa9BZRmTONbmgl64VpR6 y7i1+HkElBCvQBrL8WHZEKi5/fwtPeRuCUMSn/ls60Q79eyMd6QhiBtWX3GxNT4MGYp8 11nb/9QxumZ4BlTJ5GysRYzOaWvAzHj00rSjxO1oMgpJAy7+xmCsUuyVJq47Y+dYwGOy osmFqyGHuClwRDW+iJa87KoX8tm/0KIK2caXAOxSjFNnjbKqCC2a8w3US+/9v29bUcrP PZu9pBYIl3BK49xvwvBAieoDuq7O/p/KJg/UxTHW5Xzon4MF2mtPvf6Zs240/pKxt72f ZLtg== X-Gm-Message-State: ALoCoQk2MmUMJj9fyK+JN5BqFgqj9FlxAo3PhXvQ6n9ReJyAy6GVJL+Vv8vOeE79Pn0zgjNs9rZS MIME-Version: 1.0 X-Received: by 10.68.129.34 with SMTP id nt2mr10513600pbb.18.1400138294464; Thu, 15 May 2014 00:18:14 -0700 (PDT) Received: by 10.66.159.68 with HTTP; Thu, 15 May 2014 00:18:14 -0700 (PDT) In-Reply-To: <53744BB5.1090008@cs.ucla.edu> References: <53744BB5.1090008@cs.ucla.edu> Date: Thu, 15 May 2014 10:18:14 +0300 Message-ID: From: "Nadav Har'El" Content-Type: multipart/alternative; boundary=047d7b15a7ebada8f304f96b191b X-Spam-Score: -0.7 (/) X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -0.7 (/) --047d7b15a7ebada8f304f96b191b Content-Type: text/plain; charset=UTF-8 On Thu, May 15, 2014 at 8:08 AM, Paul Eggert 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 backslash. + +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 makefiles +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., +.EX +alias grep='grep --color=auto -n' +.EE .TP .B GREP_COLOR This variable specifies the color used to highlight matched (non-empty) text. -- Nadav Har'El nyh@cloudius-systems.com --047d7b15a7ebada8f304f96b191b Content-Type: text/html; charset=UTF-8 Content-Transfer-Encoding: quoted-printable
On T= hu, May 15, 2014 at 8:08 AM, Paul Eggert <eggert@cs.ucla.edu> wrote:
Nadav Har'El wrote:
So I think it would be best if you drop the GREP_OPTIONS feature
completely.

I tend to agree. =C2=A0Hindsight is wonderful of course, but GREP_OPTIONS s= hould never have been added, as it's a real minefield.

Yes, as they say, hindsight is always 20/20 ;-)
=C2=A0
=C2=A0But ho= w would we minimize breakage of existing usage that relies on GREP_OPTIONS?= =C2=A0If we removed it, we'd probably need a transition period, and ha= ve 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 (a= nd I just now noticed that https://savannah.gnu.org/bugs/?32501 asked for the same thing). I thin= k that the only reason people use this variable is that they read through t= he manual page, and thought it would be cool to set it to something like &q= uot;--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.
=C2=A0Option specifications are separated by whitespace.
=C2=A0A backsla= sh escapes the next character,
=C2=A0so it can be used to specify an opt= ion containing whitespace or a backslash.
+
+This variable is depreca= ted, and should be avoided. Setting it changes not
+only the behavior of
+.B grep
+in interactive shell sessions, but m= ay also break shell scripts and makefiles
+which assume that
+.B grep=
+behaves normally. A user that wishes to alter the default
+.B gre= p
+behavior only for interactive sessions should instead use the
+.I alias=
+feature provided by the shell, e.g.,
+.EX
+alias grep=3D'gre= p --color=3Dauto -n'
+.EE
=C2=A0.TP
=C2=A0.B GREP_COLOR
=C2= =A0This variable specifies the color used to highlight matched (non-empty) = text.


<= br clear=3D"all">
--
--047d7b15a7ebada8f304f96b191b-- From unknown Sat Aug 16 16:23:27 2025 X-Loop: help-debbugs@gnu.org Subject: bug#17494: grep bug report: "GREP_OPTIONS" allows a user to break shell script Resent-From: Norihiro Tanaka Original-Sender: "Debbugs-submit" Resent-CC: bug-grep@gnu.org Resent-Date: Thu, 15 May 2014 12:54:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 17494 X-GNU-PR-Package: grep X-GNU-PR-Keywords: To: Paul Eggert Cc: 17494@debbugs.gnu.org, Osv Dev , Nadav Har'El Received: via spool by 17494-submit@debbugs.gnu.org id=B17494.14001584057266 (code B ref 17494); Thu, 15 May 2014 12:54:02 +0000 Received: (at 17494) by debbugs.gnu.org; 15 May 2014 12:53:25 +0000 Received: from localhost ([127.0.0.1]:35471 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.80) (envelope-from ) id 1WkvA5-0001t6-3H for submit@debbugs.gnu.org; Thu, 15 May 2014 08:53:25 -0400 Received: from mailgw01.kcn.ne.jp ([61.86.7.208]:56770) by debbugs.gnu.org with esmtp (Exim 4.80) (envelope-from ) id 1WkvA2-0001sk-M9 for 17494@debbugs.gnu.org; Thu, 15 May 2014 08:53:23 -0400 Received: from imp03 (mailgw7.kcn.ne.jp [61.86.15.238]) by mailgw01.kcn.ne.jp (Postfix) with ESMTP id 4C6F380313 for <17494@debbugs.gnu.org>; Thu, 15 May 2014 21:53:16 +0900 (JST) Received: from mail08.kcn.ne.jp ([61.86.6.187]) by imp03 with bizsmtp id 2CtG1o00C426eXR01CtGJN; Thu, 15 May 2014 21:53:16 +0900 X-OrgRCPT: 17494@debbugs.gnu.org Received: from [10.120.1.49] (i118-21-128-66.s30.a048.ap.plala.or.jp [118.21.128.66]) by mail08.kcn.ne.jp (Postfix) with ESMTPA id 9C81912B802E; Thu, 15 May 2014 21:53:15 +0900 (JST) Date: Thu, 15 May 2014 21:53:15 +0900 From: Norihiro Tanaka In-Reply-To: <53744BB5.1090008@cs.ucla.edu> References: <53744BB5.1090008@cs.ucla.edu> Message-Id: <20140515215309.A799.27F6AC2D@kcn.ne.jp> MIME-Version: 1.0 Content-Type: text/plain; charset="US-ASCII" Content-Transfer-Encoding: 7bit X-Mailer: Becky! ver. 2.65.07 [ja] X-Spam-Score: -0.7 (/) X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -0.7 (/) I also think GREP_OPTIONS should be removed, but I'm unwilling that I won't be able to ignore the directory without a command line option. I use GREP_OPTION='-d skip' to ignore directories by default in grep 2.11 or laster. (They were ignored without a option in 2.10 or former and other imprements of grep on Solaris, HP-UX, etc.) Even if I define an alias "grep='grep -d skip'", when "find . | xargs grep" doesn't ignore directories. Norihiro From unknown Sat Aug 16 16:23:27 2025 X-Loop: help-debbugs@gnu.org Subject: bug#17494: grep bug report: "GREP_OPTIONS" allows a user to break shell script Resent-From: "Nadav Har'El" Original-Sender: "Debbugs-submit" Resent-CC: bug-grep@gnu.org Resent-Date: Thu, 15 May 2014 13:03:01 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 17494 X-GNU-PR-Package: grep X-GNU-PR-Keywords: To: Norihiro Tanaka Cc: 17494@debbugs.gnu.org, Paul Eggert , Osv Dev Received: via spool by 17494-submit@debbugs.gnu.org id=B17494.14001589329102 (code B ref 17494); Thu, 15 May 2014 13:03:01 +0000 Received: (at 17494) by debbugs.gnu.org; 15 May 2014 13:02:12 +0000 Received: from localhost ([127.0.0.1]:35481 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.80) (envelope-from ) id 1WkvIa-0002Mj-2M for submit@debbugs.gnu.org; Thu, 15 May 2014 09:02:12 -0400 Received: from mail-pa0-f53.google.com ([209.85.220.53]:43193) by debbugs.gnu.org with esmtp (Exim 4.80) (envelope-from ) id 1WkvIX-0002MV-1F for 17494@debbugs.gnu.org; Thu, 15 May 2014 09:02:09 -0400 Received: by mail-pa0-f53.google.com with SMTP id kp14so1049522pab.26 for <17494@debbugs.gnu.org>; Thu, 15 May 2014 06:02:02 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:in-reply-to:references:date :message-id:subject:from:to:cc:content-type; bh=j7hsqJ507o4Au4Bvk1IkW8maXQF4UMoDcsrwRBuXO/4=; b=Bl4ycJSnG075otfL9K+yDGdT5nN+kEp5dmKPrmN4pATOw4o/iYrg11k3sV4MVe43bq 5f1EyRN2Mi0QyXOsD0VIXnyVFO96+BxA3At3e2AeFTLAJUost875FhZRkdQkzKe/nkcH OdXVXFXx103I7fw38C02T119tWzDKka1pRH5LBqxyf8CCxbneh40kh76PPILvpa8gnqW Os4fV6vefXOM9Z0KViDgzmY66cGY8MFh+pvfRvSrM3Qc1S3pr3Zk7G90itP0Z5pJOdqX M/xytKFl89NVYutLdXB0Uwn/vEDfznzdN8hXzLJyjfmWu3+wP2QDQuoaqtkfh0Hinaer EyYQ== X-Gm-Message-State: ALoCoQnudacuZb8SQAPiDIou9osi9gNH3yDOtVQ3gL+qGJtjO9yUZqTAUjeUoMiV4o/BWrlT/iBa MIME-Version: 1.0 X-Received: by 10.66.150.169 with SMTP id uj9mr12289154pab.148.1400158922745; Thu, 15 May 2014 06:02:02 -0700 (PDT) Received: by 10.66.159.68 with HTTP; Thu, 15 May 2014 06:02:02 -0700 (PDT) In-Reply-To: <20140515215309.A799.27F6AC2D@kcn.ne.jp> References: <53744BB5.1090008@cs.ucla.edu> <20140515215309.A799.27F6AC2D@kcn.ne.jp> Date: Thu, 15 May 2014 16:02:02 +0300 Message-ID: From: "Nadav Har'El" Content-Type: multipart/alternative; boundary=047d7b6788be383da304f96fe77a X-Spam-Score: -0.7 (/) X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -0.7 (/) --047d7b6788be383da304f96fe77a Content-Type: text/plain; charset=UTF-8 On Thu, May 15, 2014 at 3:53 PM, Norihiro Tanaka wrote: > > Even if I define an alias "grep='grep -d skip'", when "find . | xargs grep" > doesn't ignore directories. > Since find does output directories, and clearly you don't want to grep on them, why not just do something like find . ! -type d | xargs grep To be even safer and work with any file name (containing even newlines), you actually need to do find . ! -type d -print0 | xargs -0 grep So maybe you just want to alias this whole thing :-) I don't think this a reason to keep GREP_OPTIONS, but like I said I don't mind if it is kept if at least people are warned about how it might break shell scripts. -- Nadav Har'El nyh@cloudius-systems.com --047d7b6788be383da304f96fe77a Content-Type: text/html; charset=UTF-8
On Thu, May 15, 2014 at 3:53 PM, Norihiro Tanaka <noritnk@kcn.ne.jp> wrote:

Even if I define an alias "grep='grep -d skip'", when "find . | xargs grep"
doesn't ignore directories.

Since find does output directories, and clearly you don't want to grep on them, why not just do something like

find . ! -type d | xargs grep

To be even safer and work with any file name (containing even newlines), you actually need to do

find . ! -type d -print0 | xargs -0 grep

So maybe you just want to alias this whole thing :-)

I don't think this a reason to keep GREP_OPTIONS, but like I said I don't mind if it is kept if at least people are warned about how it might break shell scripts.


--
--047d7b6788be383da304f96fe77a-- From debbugs-submit-bounces@debbugs.gnu.org Fri May 16 00:38:42 2014 Received: (at control) by debbugs.gnu.org; 16 May 2014 04:38:43 +0000 Received: from localhost ([127.0.0.1]:36583 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.80) (envelope-from ) id 1Wl9us-0007Io-Ia for submit@debbugs.gnu.org; Fri, 16 May 2014 00:38:42 -0400 Received: from smtp.cs.ucla.edu ([131.179.128.62]:56720) by debbugs.gnu.org with esmtp (Exim 4.80) (envelope-from ) id 1Wl9up-0007I5-E7 for control@debbugs.gnu.org; Fri, 16 May 2014 00:38:39 -0400 Received: from localhost (localhost.localdomain [127.0.0.1]) by smtp.cs.ucla.edu (Postfix) with ESMTP id 026ABA60061 for ; Thu, 15 May 2014 21:38:34 -0700 (PDT) X-Virus-Scanned: amavisd-new at smtp.cs.ucla.edu Received: from smtp.cs.ucla.edu ([127.0.0.1]) by localhost (smtp.cs.ucla.edu [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id B8C8sNjlqiOe for ; Thu, 15 May 2014 21:38:25 -0700 (PDT) Received: from [192.168.1.9] (pool-108-0-233-62.lsanca.fios.verizon.net [108.0.233.62]) by smtp.cs.ucla.edu (Postfix) with ESMTPSA id 7C8B5A60035 for ; Thu, 15 May 2014 21:38:25 -0700 (PDT) Message-ID: <53759641.8090509@cs.ucla.edu> Date: Thu, 15 May 2014 21:38:25 -0700 From: Paul Eggert Organization: UCLA Computer Science Department User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:24.0) Gecko/20100101 Thunderbird/24.5.0 MIME-Version: 1.0 To: control@debbugs.gnu.org Subject: grep bug report cleanup Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Spam-Score: -3.0 (---) X-Debbugs-Envelope-To: control X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -3.0 (---) tags 17501 + moreinfo severity 17501 minor severity 17494 wishlist From unknown Sat Aug 16 16:23:27 2025 X-Loop: help-debbugs@gnu.org Subject: bug#17494: "GREP_OPTIONS" allows a user to break shell script References: In-Reply-To: Resent-From: Paul Eggert Original-Sender: "Debbugs-submit" Resent-CC: bug-grep@gnu.org Resent-Date: Thu, 11 Sep 2014 21:23:01 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 17494 X-GNU-PR-Package: grep X-GNU-PR-Keywords: To: Nadav Har'El , 17494@debbugs.gnu.org Received: via spool by 17494-submit@debbugs.gnu.org id=B17494.141047052420702 (code B ref 17494); Thu, 11 Sep 2014 21:23:01 +0000 Received: (at 17494) by debbugs.gnu.org; 11 Sep 2014 21:22:04 +0000 Received: from localhost ([127.0.0.1]:38542 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.80) (envelope-from ) id 1XSBoY-0005Nl-SR for submit@debbugs.gnu.org; Thu, 11 Sep 2014 17:22:03 -0400 Received: from smtp.cs.ucla.edu ([131.179.128.62]:60287) by debbugs.gnu.org with esmtp (Exim 4.80) (envelope-from ) id 1XSBoV-0005NH-Tl for 17494@debbugs.gnu.org; Thu, 11 Sep 2014 17:22:01 -0400 Received: from localhost (localhost.localdomain [127.0.0.1]) by smtp.cs.ucla.edu (Postfix) with ESMTP id 49DFFA6001D; Thu, 11 Sep 2014 14:21:59 -0700 (PDT) X-Virus-Scanned: amavisd-new at smtp.cs.ucla.edu Received: from smtp.cs.ucla.edu ([127.0.0.1]) by localhost (smtp.cs.ucla.edu [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id jHsl+on5Nj8Y; Thu, 11 Sep 2014 14:21:54 -0700 (PDT) Received: from penguin.cs.ucla.edu (Penguin.CS.UCLA.EDU [131.179.64.200]) by smtp.cs.ucla.edu (Postfix) with ESMTPSA id 63115A60001; Thu, 11 Sep 2014 14:21:54 -0700 (PDT) Message-ID: <54121272.4030705@cs.ucla.edu> Date: Thu, 11 Sep 2014 14:21:54 -0700 From: Paul Eggert Organization: UCLA Computer Science Department User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:31.0) Gecko/20100101 Thunderbird/31.1.0 MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="------------080908010405050605050506" X-Spam-Score: -4.8 (----) X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -4.8 (----) This is a multi-part message in MIME format. --------------080908010405050605050506 Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 7bit Attached is a proposed patch that starts to address this longstanding problem by deprecating GREP_OPTIONS and warning if it's used. We can remove the dangerous feature in a later release. Comments? --------------080908010405050605050506 Content-Type: text/x-patch; name="0001-grep-make-GREP_OPTIONS-obsolescent.patch" Content-Transfer-Encoding: 7bit Content-Disposition: attachment; filename="0001-grep-make-GREP_OPTIONS-obsolescent.patch" >From be556580362361bbcbef5cd99e849bd99f6f0960 Mon Sep 17 00:00:00 2001 From: Paul Eggert Date: Thu, 11 Sep 2014 14:16:48 -0700 Subject: [PATCH] grep: make GREP_OPTIONS obsolescent * NEWS: * doc/grep.in.1 (ENVIRONMENT_VARIABLES): * doc/grep.texi (Environment Variables): Document that GREP_OPTIONS is obsolescent now. * src/grep.c (main): Warn if GREP_OPTIONS is used. * tests/r-dot, tests/skip-device: Don't use GREP_OPTIONS. --- NEWS | 3 +++ doc/grep.in.1 | 18 ++++++------------ doc/grep.texi | 19 +++---------------- src/grep.c | 5 +++++ tests/r-dot | 3 +-- tests/skip-device | 3 --- 6 files changed, 18 insertions(+), 33 deletions(-) diff --git a/NEWS b/NEWS index ca79525..05edd65 100644 --- a/NEWS +++ b/NEWS @@ -29,6 +29,9 @@ GNU grep NEWS -*- outline -*- ** Changes in behavior + The GREP_OPTIONS environment variable is now obsolescent, and grep + now warns if it is used. Please use an alias or script instead. + grep --exclude-dir='FOO/' now excludes the directory FOO. Previously, the trailing slash meant the option was ineffective. diff --git a/doc/grep.in.1 b/doc/grep.in.1 index 63c6081..00d030a 100644 --- a/doc/grep.in.1 +++ b/doc/grep.in.1 @@ -851,19 +851,13 @@ was not compiled with national language support (\s-1NLS\s0). .B GREP_OPTIONS This variable specifies default options to be placed in front of any explicit options. -For example, if -.B GREP_OPTIONS -is -.BR "'\-\^\-binary-files=without-match \-\^\-directories=skip'" , -.B grep -behaves as if the two options -.B \-\^\-binary\-files=without-match +As this causes problems when writing portable scripts, +this feature will be removed in a future release of +.BR grep , and -.B \-\^\-directories=skip -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 backslash. +.B grep +warns if it is used. +Please use an alias or script instead. .TP .B GREP_COLOR This variable specifies the color used to highlight matched (non-empty) text. diff --git a/doc/grep.texi b/doc/grep.texi index 02181b0..c8e4acd 100644 --- a/doc/grep.texi +++ b/doc/grep.texi @@ -824,22 +824,9 @@ the @code{terminfo} library. @cindex default options environment variable This variable specifies default options to be placed in front of any explicit options. -For example, if @env{GREP_OPTIONS} is -@samp{--binary-files=without-match --directories=skip}, @command{grep} -behaves as if the two options @samp{--binary-files=without-match} and -@samp{--directories=skip} 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 backslash. - -The @env{GREP_OPTIONS} value does not affect whether @command{grep} -without file operands searches standard input or the working -directory; that is affected only by command-line options. For -example, the command @samp{grep PAT} searches standard input and the -command @samp{grep -r PAT} searches the working directory, regardless -of whether @env{GREP_OPTIONS} contains @option{-r}. +As this causes problems when writing portable scripts, this feature +will be removed in a future release of @command{grep}, and @command{grep} +warns if it is used. Please use an alias or script instead. @item GREP_COLOR @vindex GREP_COLOR @r{environment variable} diff --git a/src/grep.c b/src/grep.c index 6b930dc..1f801e9 100644 --- a/src/grep.c +++ b/src/grep.c @@ -1973,7 +1973,12 @@ main (int argc, char **argv) atexit (clean_up_stdout); last_recursive = 0; + prepended = prepend_default_options (getenv ("GREP_OPTIONS"), &argc, &argv); + if (prepended) + error (0, 0, _("warning: GREP_OPTIONS is deprecated;" + " please use an alias or script")); + compile = matchers[0].compile; execute = matchers[0].execute; diff --git a/tests/r-dot b/tests/r-dot index a1d5c0a..29aedad 100755 --- a/tests/r-dot +++ b/tests/r-dot @@ -14,8 +14,7 @@ compare exp out || fail=1 (cd dir && grep -r aaa < a) > out || fail=1 compare exp out || fail=1 -echo aaa > exp || framework_failure_ -(cd dir && GREP_OPTIONS=-r grep aaa < a) > out || fail=1 +(cd dir && grep -r aaa *) > out || fail=1 compare exp out || fail=1 Exit $fail diff --git a/tests/skip-device b/tests/skip-device index 40645ea..32663fe 100755 --- a/tests/skip-device +++ b/tests/skip-device @@ -8,7 +8,4 @@ echo foo | grep -D skip foo - || fail=1 echo foo | grep --devices=skip foo || fail=1 -# It's more insidious when the skip option is via the envvar: -echo foo | GREP_OPTIONS=--devices=skip grep foo || fail=1 - Exit $fail -- 1.9.3 --------------080908010405050605050506-- From debbugs-submit-bounces@debbugs.gnu.org Thu Sep 11 17:22:39 2014 Received: (at control) by debbugs.gnu.org; 11 Sep 2014 21:22:39 +0000 Received: from localhost ([127.0.0.1]:38548 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.80) (envelope-from ) id 1XSBp9-0005Ou-4K for submit@debbugs.gnu.org; Thu, 11 Sep 2014 17:22:39 -0400 Received: from smtp.cs.ucla.edu ([131.179.128.62]:60347) by debbugs.gnu.org with esmtp (Exim 4.80) (envelope-from ) id 1XSBp5-0005Oc-Ge for control@debbugs.gnu.org; Thu, 11 Sep 2014 17:22:36 -0400 Received: from localhost (localhost.localdomain [127.0.0.1]) by smtp.cs.ucla.edu (Postfix) with ESMTP id 136B9A6001E for ; Thu, 11 Sep 2014 14:22:35 -0700 (PDT) X-Virus-Scanned: amavisd-new at smtp.cs.ucla.edu Received: from smtp.cs.ucla.edu ([127.0.0.1]) by localhost (smtp.cs.ucla.edu [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id iXHleoIryZGa for ; Thu, 11 Sep 2014 14:22:26 -0700 (PDT) Received: from penguin.cs.ucla.edu (Penguin.CS.UCLA.EDU [131.179.64.200]) by smtp.cs.ucla.edu (Postfix) with ESMTPSA id 8C146A6001D for ; Thu, 11 Sep 2014 14:22:26 -0700 (PDT) Message-ID: <54121292.4040508@cs.ucla.edu> Date: Thu, 11 Sep 2014 14:22:26 -0700 From: Paul Eggert Organization: UCLA Computer Science Department User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:31.0) Gecko/20100101 Thunderbird/31.1.0 MIME-Version: 1.0 To: control@debbugs.gnu.org Subject: 17494 has a patch Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 7bit X-Spam-Score: -4.8 (----) X-Debbugs-Envelope-To: control X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -4.8 (----) tags 17494 patch From unknown Sat Aug 16 16:23:27 2025 X-Loop: help-debbugs@gnu.org Subject: bug#17494: "GREP_OPTIONS" allows a user to break shell script Resent-From: Jim Meyering Original-Sender: "Debbugs-submit" Resent-CC: bug-grep@gnu.org Resent-Date: Fri, 12 Sep 2014 15:25:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 17494 X-GNU-PR-Package: grep X-GNU-PR-Keywords: patch To: Paul Eggert Cc: 17494@debbugs.gnu.org, Nadav Har'El Received: via spool by 17494-submit@debbugs.gnu.org id=B17494.141053548513241 (code B ref 17494); Fri, 12 Sep 2014 15:25:02 +0000 Received: (at 17494) by debbugs.gnu.org; 12 Sep 2014 15:24:45 +0000 Received: from localhost ([127.0.0.1]:39571 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.80) (envelope-from ) id 1XSSiG-0003RR-ME for submit@debbugs.gnu.org; Fri, 12 Sep 2014 11:24:44 -0400 Received: from mail-wi0-f179.google.com ([209.85.212.179]:54447) by debbugs.gnu.org with esmtp (Exim 4.80) (envelope-from ) id 1XSSiD-0003RH-KX for 17494@debbugs.gnu.org; Fri, 12 Sep 2014 11:24:38 -0400 Received: by mail-wi0-f179.google.com with SMTP id hi2so865837wib.6 for <17494@debbugs.gnu.org>; Fri, 12 Sep 2014 08:24:36 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:sender:in-reply-to:references:from:date:message-id :subject:to:cc:content-type; bh=Lgx7xmP2OvHxAVRKRS/lcWdGCKI5iF23ZI+MAPXvNys=; b=Lt5cuVZ7e65sv+tWtCpwpocKEcR9mD2rGbOFVpYKhZfx3bzWjGKKSgWS1Xhcgk8Dcf 7oXyVKqtjdhl7lxB4vjeSIllQ3Wr0glF89tHsSDl77an8Sq9WvZjF+z/BPzGxgJuoV67 sfKIime7R2CKfe+FgmzYE6AQ+Ey3EnBknt1xSMCxImqqDUxoJXANE/YjbB9cvNS9Cc6L lqPoyRTYHHwZr3JRQS/onyy/celSIderoYNcSniq4c/0YvQmloJzcocrqR6L/UoqeSGd yFTFP9TXStKD73901wnmj6M33qTh7cz88TVW23UTXMZzYMP9z8gttM+evY4VHg8Nz7Yh ooZA== X-Received: by 10.194.108.41 with SMTP id hh9mr11980698wjb.68.1410535475587; Fri, 12 Sep 2014 08:24:35 -0700 (PDT) MIME-Version: 1.0 Received: by 10.194.41.202 with HTTP; Fri, 12 Sep 2014 08:24:15 -0700 (PDT) In-Reply-To: <54121272.4030705@cs.ucla.edu> References: <54121272.4030705@cs.ucla.edu> From: Jim Meyering Date: Fri, 12 Sep 2014 08:24:15 -0700 X-Google-Sender-Auth: OI0gFSXovaLxwfcGQcAa1c0TLo0 Message-ID: Content-Type: text/plain; charset=ISO-8859-1 X-Spam-Score: -0.7 (/) X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -0.7 (/) On Thu, Sep 11, 2014 at 2:21 PM, Paul Eggert wrote: > Attached is a proposed patch that starts to address this longstanding > problem by deprecating GREP_OPTIONS and warning if it's used. We can remove > the dangerous feature in a later release. Comments? That looks fine. Long overdue. Thank you for writing it. From unknown Sat Aug 16 16:23:27 2025 MIME-Version: 1.0 X-Mailer: MIME-tools 5.503 (Entity 5.503) X-Loop: help-debbugs@gnu.org From: help-debbugs@gnu.org (GNU bug Tracking System) To: "Nadav Har'El" Subject: bug#17494: closed (Re: bug#17494: "GREP_OPTIONS" allows a user to break shell script) Message-ID: References: <541319DF.2060008@cs.ucla.edu> X-Gnu-PR-Message: they-closed 17494 X-Gnu-PR-Package: grep X-Gnu-PR-Keywords: patch Reply-To: 17494@debbugs.gnu.org Date: Fri, 12 Sep 2014 16:07:02 +0000 Content-Type: multipart/mixed; boundary="----------=_1410538022-17223-1" This is a multi-part message in MIME format... ------------=_1410538022-17223-1 Content-Disposition: inline Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Your bug report #17494: grep bug report: "GREP_OPTIONS" allows a user to break shell script which was filed against the grep package, has been closed. The explanation is attached below, along with your original report. If you require more details, please reply to 17494@debbugs.gnu.org. --=20 17494: http://debbugs.gnu.org/cgi/bugreport.cgi?bug=3D17494 GNU Bug Tracking System Contact help-debbugs@gnu.org with problems ------------=_1410538022-17223-1 Content-Type: message/rfc822 Content-Disposition: inline Content-Transfer-Encoding: 7bit Received: (at 17494-done) by debbugs.gnu.org; 12 Sep 2014 16:06:04 +0000 Received: from localhost ([127.0.0.1]:39580 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.80) (envelope-from ) id 1XSTMJ-0004SS-SF for submit@debbugs.gnu.org; Fri, 12 Sep 2014 12:06:04 -0400 Received: from smtp.cs.ucla.edu ([131.179.128.62]:42651) by debbugs.gnu.org with esmtp (Exim 4.80) (envelope-from ) id 1XSTMH-0004S3-Ps for 17494-done@debbugs.gnu.org; Fri, 12 Sep 2014 12:06:02 -0400 Received: from localhost (localhost.localdomain [127.0.0.1]) by smtp.cs.ucla.edu (Postfix) with ESMTP id 01EB1A6001D; Fri, 12 Sep 2014 09:06:00 -0700 (PDT) X-Virus-Scanned: amavisd-new at smtp.cs.ucla.edu Received: from smtp.cs.ucla.edu ([127.0.0.1]) by localhost (smtp.cs.ucla.edu [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id pCxZ9k8gRtjL; Fri, 12 Sep 2014 09:05:51 -0700 (PDT) Received: from [192.168.1.9] (pool-71-177-17-123.lsanca.dsl-w.verizon.net [71.177.17.123]) by smtp.cs.ucla.edu (Postfix) with ESMTPSA id 53FEDA60022; Fri, 12 Sep 2014 09:05:51 -0700 (PDT) Message-ID: <541319DF.2060008@cs.ucla.edu> Date: Fri, 12 Sep 2014 09:05:51 -0700 From: Paul Eggert Organization: UCLA Computer Science Department User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:31.0) Gecko/20100101 Thunderbird/31.1.1 MIME-Version: 1.0 To: Jim Meyering Subject: Re: bug#17494: "GREP_OPTIONS" allows a user to break shell script References: <54121272.4030705@cs.ucla.edu> In-Reply-To: Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 7bit X-Spam-Score: -4.5 (----) X-Debbugs-Envelope-To: 17494-done Cc: 17494-done@debbugs.gnu.org, Nadav Har'El X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -4.5 (----) Jim Meyering wrote: > That looks fine. Long overdue. Thank you for writing it. You're welcome, and I applied it and am marking this as done. Other GNU utilities probably need similar changes at some point. ------------=_1410538022-17223-1 Content-Type: message/rfc822 Content-Disposition: inline Content-Transfer-Encoding: 7bit Received: (at submit) by debbugs.gnu.org; 14 May 2014 22:20:15 +0000 Received: from localhost ([127.0.0.1]:34958 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.80) (envelope-from ) id 1WkhX3-0008AG-Je for submit@debbugs.gnu.org; Wed, 14 May 2014 18:20:14 -0400 Received: from eggs.gnu.org ([208.118.235.92]:39228) by debbugs.gnu.org with esmtp (Exim 4.80) (envelope-from ) id 1WkhFC-0007bp-3w for submit@debbugs.gnu.org; Wed, 14 May 2014 18:01:46 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1WkhF1-0008A9-Pz for submit@debbugs.gnu.org; Wed, 14 May 2014 18:01:41 -0400 X-Spam-Checker-Version: SpamAssassin 3.3.2 (2011-06-06) on eggs.gnu.org X-Spam-Level: X-Spam-Status: No, score=0.8 required=5.0 tests=BAYES_50,HTML_MESSAGE autolearn=disabled version=3.3.2 Received: from lists.gnu.org ([2001:4830:134:3::11]:33142) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1WkhF1-0008A5-Nc for submit@debbugs.gnu.org; Wed, 14 May 2014 18:01:35 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:40905) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1WkhEw-00047b-W9 for bug-grep@gnu.org; Wed, 14 May 2014 18:01:35 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1WkhEs-0007wB-8Z for bug-grep@gnu.org; Wed, 14 May 2014 18:01:30 -0400 Received: from mail-pa0-f54.google.com ([209.85.220.54]:43064) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1WkhEs-0007uy-0W for bug-grep@gnu.org; Wed, 14 May 2014 18:01:26 -0400 Received: by mail-pa0-f54.google.com with SMTP id bj1so153255pad.27 for ; Wed, 14 May 2014 15:01:24 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:date:message-id:subject:from:to:cc :content-type; bh=iN5aN0hQ0GgLtLYSTvn7YOxICnFCeGNkaFLQX5C4V24=; b=aEq3wUhWXDL8bIK0r02mtAL8orkIGarXN5pwVnVy9rJMnuZ8J5nd5V6EOjgZFRL7Sm KndFpbqv1lxX6jMkyjAVXZklfqWCXkxCwdrNAyE/SsH27bR9/yiyZM7aogdL9e97L65Z gjFHvoA2CY2CbnqWi82VzWeKPfyea/AL01t2+kTOGxpy+mrVS2bJcdsQwk3L6vOzyxf2 SdA/tvFTKxQA82mzzF2cRv6E1FtBOo/zCIb1Danyq1o5KuJUASyB+i0xe85OKG9RFBcD GEFzcHJLX7FojDpCpztZdDmQBt6i8aUyLbK6yniklbbn59GYivhD7djZTl5Utr6iI1MR PQXg== X-Gm-Message-State: ALoCoQnDs46W/S+0V9yVBgRLKr/sIbzCTy9PFiuJ+bip1CmBMiC6S0vGS/H2DWfAR7zScJGuz3tM MIME-Version: 1.0 X-Received: by 10.68.193.100 with SMTP id hn4mr7635240pbc.50.1400104884441; Wed, 14 May 2014 15:01:24 -0700 (PDT) Received: by 10.66.159.68 with HTTP; Wed, 14 May 2014 15:01:24 -0700 (PDT) Date: Thu, 15 May 2014 01:01:24 +0300 Message-ID: Subject: grep bug report: "GREP_OPTIONS" allows a user to break shell script From: "Nadav Har'El" To: bug-grep@gnu.org Content-Type: multipart/alternative; boundary=047d7bd6aa9c492bb304f963526b X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-detected-operating-system: by eggs.gnu.org: Error: Malformed IPv6 address (bad octet value). X-Received-From: 2001:4830:134:3::11 X-Spam-Score: -4.3 (----) X-Debbugs-Envelope-To: submit X-Mailman-Approved-At: Wed, 14 May 2014 18:20:11 -0400 Cc: Osv Dev X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -4.3 (----) --047d7bd6aa9c492bb304f963526b Content-Type: text/plain; charset=UTF-8 Hi, An unsuspecting user who reads the grep(1) manual page and discovers the GREP_OPTIONS environment variable, might thing it is a cool idea to set it. For example, set GREP_OPTIONS=-n to always get numbers on the output, great isn't it? Well, it's actually a really bad idea to export GREP_OPTIONS=-n, or anything similar, because this will effect not only the user's interactive work in his shell, but also likely break any shell-script, makefile, and so on, which happens to use "grep" and assume that it behaves normally. Imagine what kind a mess a user could cause by setting GREP_OPTIONS=-v :-) Instead of setting GREP_OPTIONS hoping it will only effect his interactive session, what the user should have done is to use an *alias*, e.g., alias grep='grep -n' In fact on my Fedora installation, there is already a similar alias by default: alias grep='grep --color=auto' These aliases (when put in .bashrc or similar) are safe - they only effect the user's interactive shell, and *not* shell scripts or makefiles, which use the normal grep as they expect. So I think it would be best if you drop the GREP_OPTIONS feature completely. Or if for some reason you really don't want to drop it, please at least explain in the manual page why it is dangerous and aliases should be preferred. An example of the kind of damage the availability of this option can do is that today, a user of an open-source project I'm working on (OSv), asked us to replace every use of "grep" in our makefile to calls to "GREP_OPTIONS= grep", so that grep will continue to work normally even for people who set GREP_OPTIONS. A final remark: Other command-line utilities, such as "ls", "rm", "cat" and so on, also don't have a .._OPTIONS variable of the sort grep has. Imagine what kind of havoc users could cause to shell scripts if they could do RM_OPTIONS=-i. Instead, what users have been doing for many years is to alias ls, rm, and so on. They can change "rm" to "rm -i" for themselves, but it won't mess with non-interactive shell-scripts. There is no reason, I think, why grep needs to be any different. Thanks, Nadav. -- Nadav Har'El nyh@cloudius-systems.com --047d7bd6aa9c492bb304f963526b Content-Type: text/html; charset=UTF-8 Content-Transfer-Encoding: quoted-printable
Hi,

An unsuspecting user who r= eads the grep(1) manual page and discovers
the GREP_OPTIONS enviro= nment variable, might thing it is a cool idea to
set it. For example, se= t GREP_OPTIONS=3D-n to always get numbers on the
output, great isn't it?

Well, it's actually a really bad ide= a to export GREP_OPTIONS=3D-n, or anything
similar, because this will ef= fect not only the user's interactive work in his shell,
but also lik= ely break any shell-script, makefile, and so on, which happens to
use "grep" and assume that it behaves normally. Imagine what kind= a mess
a user could cause by setting GREP_OPTIONS=3D-v :-)

Instead of setting GREP_OPTIONS hoping it will only effect his intera= ctive
session, what the user should have done is to use an *alias*, e.g.,

=
=C2=A0=C2=A0=C2=A0 alias grep=3D'grep -n'

In fact= on my Fedora installation, there is already a similar alias by default:

=C2=A0=C2=A0=C2=A0 alias grep=3D'grep --color=3Dauto'
These aliases (when put in .bashrc or similar) are safe - t= hey only effect
the user's interactive shell, and *not* s= hell scripts or makefiles, which
use the normal grep as they expect.

So I think it would b= e best if you drop the GREP_OPTIONS feature
completely. Or if= for some reason you really don't want to drop it,
please at least e= xplain in the manual page why it is dangerous
and aliases should be preferred.

An example of the kind of dam= age the availability of this option can do
is that today, a user of= an open-source project I'm working on (OSv),
asked us to= replace every use of "grep" in our makefile to calls to
"GREP_OPTIONS=3D grep", so that grep will continue to = work normally
even for people who set GREP_OPTIONS.

A final = remark: Other command-line utilities, such as "ls", "rm"= ;, "cat"
and so on, also don't have a .._OPTIONS variable of the sort grep has.<= br>Imagine what kind of havoc users could cause to shell scripts if theycould do RM_OPTIONS=3D-i. Instead, what users have been doing for
many = years is to alias ls, rm, and so on. They can change "rm" to &quo= t;rm -i"
for themselves, but it won't mess with non-interactive shell-scripts.
There is no reason, I think, why grep needs to be any differen= t.

Thanks,
Nadav.

--
Nadav Har'El
<= a href=3D"mailto:nyh@cloudius-systems.com" target=3D"_blank">nyh@cloudius-s= ystems.com
--047d7bd6aa9c492bb304f963526b-- ------------=_1410538022-17223-1-- From unknown Sat Aug 16 16:23:27 2025 X-Loop: help-debbugs@gnu.org Subject: bug#17494: "GREP_OPTIONS" allows a user to break shell script Resent-From: "Nadav Har'El" Original-Sender: "Debbugs-submit" Resent-CC: bug-grep@gnu.org Resent-Date: Sat, 13 Sep 2014 21:38:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 17494 X-GNU-PR-Package: grep X-GNU-PR-Keywords: patch To: Paul Eggert Cc: 17494@debbugs.gnu.org Received: via spool by 17494-submit@debbugs.gnu.org id=B17494.141064427429080 (code B ref 17494); Sat, 13 Sep 2014 21:38:02 +0000 Received: (at 17494) by debbugs.gnu.org; 13 Sep 2014 21:37:54 +0000 Received: from localhost ([127.0.0.1]:40431 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.80) (envelope-from ) id 1XSv0y-0007Yx-Th for submit@debbugs.gnu.org; Sat, 13 Sep 2014 17:37:53 -0400 Received: from mail-pa0-f50.google.com ([209.85.220.50]:56411) by debbugs.gnu.org with esmtp (Exim 4.80) (envelope-from ) id 1XSv0w-0007Yo-I9 for 17494@debbugs.gnu.org; Sat, 13 Sep 2014 17:37:51 -0400 Received: by mail-pa0-f50.google.com with SMTP id bj1so3776627pad.9 for <17494@debbugs.gnu.org>; Sat, 13 Sep 2014 14:37:49 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:in-reply-to:references:date :message-id:subject:from:to:cc:content-type; bh=L0Bcdqhd7pmjYn/1fbY4Vpbldb8j3DAWQmGLXUfEgpk=; b=NPBSnshYwKiqg4K6r9GrFgPWo/MyLqJc3jxo1X8ET1ZPJT3bHAYaN+2U/fm7Z3hPgu +wPXGuWHjHdSmzVVuPVU7vwpL6Yk8o990ivyCYF9TCgMtnN0aRBJy11x2Hv4DOnTGsV4 SEM9U6zWzlp34VuqEWwHNGGKYjYrq9pTlsQi1xXCYKGamMlLlJitHKiJND3179TISIQ1 ody2Fdb5ofjGzh4qxOEViCiRjebD1S1EFDmbzGdoScLcVVMX/De6ez4eKJ/gXFw2bSrt cXrOKUBdgLULrMsMuDMDX8YIbhWYldjZlOQDGpC7OF/pfCNk9+srEN92DCXzmBl6cSlq I9FA== X-Gm-Message-State: ALoCoQmar4Hzf06gZ0yQ//RWPW0tozuzsvjrHIkKHNyBFmjaIa5c+IMpFKdpferQW/Pl4vNtT3AZ MIME-Version: 1.0 X-Received: by 10.70.94.3 with SMTP id cy3mr14926829pdb.114.1410644269399; Sat, 13 Sep 2014 14:37:49 -0700 (PDT) Received: by 10.66.241.10 with HTTP; Sat, 13 Sep 2014 14:37:49 -0700 (PDT) In-Reply-To: <54121272.4030705@cs.ucla.edu> References: <54121272.4030705@cs.ucla.edu> Date: Sun, 14 Sep 2014 00:37:49 +0300 Message-ID: From: "Nadav Har'El" Content-Type: multipart/alternative; boundary=047d7b67702e951c4f0502f93625 X-Spam-Score: -0.7 (/) X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -0.7 (/) --047d7b67702e951c4f0502f93625 Content-Type: text/plain; charset=UTF-8 On Fri, Sep 12, 2014 at 12:21 AM, Paul Eggert wrote: > Attached is a proposed patch that starts to address this longstanding > problem by deprecating GREP_OPTIONS and warning if it's used. We can > remove the dangerous feature in a later release. Comments? > Looks good to me. However, it seems to me that if grep prints this "warning:" every time grep is used, we don't just deprecate this feature (with a promise to remove it later), we actually make this feature unusable immediately, because nobody wants to see this message on every invocation of grep. But I'm personally fine with this change, if you are. Thanks, Nadav. -- Nadav Har'El nyh@cloudius-systems.com --047d7b67702e951c4f0502f93625 Content-Type: text/html; charset=UTF-8 Content-Transfer-Encoding: quoted-printable
On F= ri, Sep 12, 2014 at 12:21 AM, Paul Eggert <eggert@cs.ucla.edu> wrote:
Attached is a proposed patch t= hat starts to address this longstanding problem by deprecating GREP_OPTIONS= and warning if it's used.=C2=A0 We can remove the dangerous feature in= a later release.=C2=A0 Comments?

Looks= good to me. However, it seems to me that if grep prints this "warning= :" every time grep is used, we don't just deprecate this feature (= with a promise to remove it later), we actually make this feature unusable = immediately, because nobody wants to see this message on every invocation o= f grep.

But I'm personally fine with this change, if = you are.

Thanks,
Nadav.


--
--047d7b67702e951c4f0502f93625--