Subject: Re: bug#19998: GREP_OPTIONS alternative?

From: Paul Eggert <[email-masked]>
Date: Wed, 11 Mar 2015 17:58:42 -0700

Christian Kujau wrote:
> On a Debian/Linux or a
> SuSE Linux system,/bin/*grep are not symlinks to /bin/grep but
> seperate executables.

On my Ubuntu 14.10 system, fgrep lives in /bin and is a separate executable 
(actually a shell script), but it invokes 'grep'.  Likewise for Fedora 21, where 
fgrep lives in /usr/bin.  So what you write doesn't necessarily contradict what 
I said.

On the other hand, now that I've tested it, I see that when I type 'fgrep' Bash 
invokes it as '/bin/fgrep', which surprises me and which defeats the purpose of 
having 'fgrep' look at $0.  I installed the attached patch, which should fix that.

> Why is GREP_OPTIONS random and LESS or ZIPOPT or GZIP are not?

For starters, none of the other variables are used by standard utilities. 
Admittedly some judgment is needed here.  As LESS is merely a user-interface 
thing it's less worrisome.  I don't know what ZIPOPT is.  GZIP is worrisome and 
probably should go -- an attacker can use GZIP to cause 'gzip' to remove 
/etc/passwd, for example.  So it looks like I should add removing GZIP to my 
list of things to do too....
>From f8471e3d5d7d90de5e36068a1ddc60f3987e3bfb Mon Sep 17 00:00:00 2001
From: Paul Eggert <[email-masked]>
Date: Wed, 11 Mar 2015 17:55:37 -0700
Subject: [PATCH] egrep, fgrep: just use what's in PATH

* src/egrep.sh: Don't monkey with PATH; just use whatever 'grep'
is in the path.  This is simpler, and lets the user specify
default options with a script for only grep, with no need for
egrep and fgrep scripts.
Fixes: bug#19998
---
 src/egrep.sh | 11 +----------
 1 file changed, 1 insertion(+), 10 deletions(-)

diff --git a/src/egrep.sh b/src/egrep.sh
index 1a03d2a..6d6c15a 100644
--- a/src/egrep.sh
+++ b/src/egrep.sh
@@ -1,11 +1,2 @@
 #!@SHELL@
-grep=grep
-case $0 in
-  */*)
-    dir=${0%/*}
-    if test -x "$dir/@grep@"; then
-      PATH=$dir:$PATH
-      grep=@grep@
-    fi;;
-esac
-exec $grep @option@ "$@"
+exec @grep@ @option@ "$@"
-- 
2.1.0