Subject: bug#20883: closed (Re: bug#20883: egrep on Solaris fails to call original grep binary)

From: [email-masked] (GNU bug Tracking System)
Date: Fri, 26 Jun 2015 20:41:04 +0000

Your bug report

#20883: egrep on Solaris fails to call original grep binary

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 [email-masked].

-- 
20883: http://debbugs.gnu.org/cgi/bugreport.cgi?bug=20883
GNU Bug Tracking System
Contact [email-masked] with problems

Subject: Re: bug#20883: egrep on Solaris fails to call original grep binary
From: Paul Eggert <[email-masked]>
To: Vladimir Marek <[email-masked]>
Cc: [email-masked]
Date: Fri, 26 Jun 2015 13:40:03 -0700
List-Id: <debbugs-submit.debbugs.gnu.org>

Thanks for following up; sounds like grep is OK then, so closing the bug.

Subject: egrep on Solaris fails to call original grep binary
From: Vladimir Marek <[email-masked]>
To: [email-masked]
Date: Tue, 23 Jun 2015 17:39:15 +0200
List-Id: <debbugs-submit.debbugs.gnu.org>

Hi,

$ PATH=/usr/bin gegrep
grep: illegal option -- E
Usage: grep [-c|-l|-q] -bhinsvw pattern file . . .

The gegrep script:

#!/bin/bash
grep=grep
case $0 in
  */*)
    dir=${0%/*}
    if test -x "$dir/grep"; then
      PATH=$dir:$PATH
      grep=grep
    fi;;
esac
exec $grep -E "$@"

The problem is that in the case when egrep is called without specifying full
path (there's no '/' in $0), it calls the grep binary (with -E option) in
default PATH. In the case of Solaris /usr/bin/grep is not a GNU grep, thus
error message about missing -E option.

I can see two possibilities of fixing it

a) As the GNU grep is called 'ggrep' on Solaris, we should use

grep=ggrep

and all is good. No need to change anything in GNU grep, just keep our
local Solaris patch.

b) As the GNU grep is available on /usr/gnu/bin path too (users who
deserve to have GNU commandline behavior use /usr/gnu/bin before
/usr/bin in PATH), we should use the /usr/gnu/bin prefix path for grep:

--- grep-2.20/src/egrep.sh      2015-06-23 14:03:57.123888876 +0200
+++ grep-2.20/src/egrep.sh      2015-06-23 14:03:27.529153050 +0200
@@ -7,5 +7,8 @@ case $0 in
       PATH=$dir:$PATH
       grep=@grep@
     fi;;
+  *)
+    PATH="@prefix@/bin:$PATH"
+    ;;
 esac
 exec $grep @option@ "$@"
--- grep-2.20/src/Makefile.am  2015-06-23 07:17:45.984838354 -0700
+++ grep-2.20/src/Makefile.am  2015-06-23 07:17:45.052710962 -0700
@@ -56,6 +56,7 @@ egrep fgrep: egrep.sh Makefile
       sed -e 's|[@]SHELL@|$(SHELL)|g' \
           -e "$$edit_substring" \
           -e "s|[@]grep@|$$grep|g" \
+          -e "s|[@]prefix@|$(prefix)|g" \
           -e "s|[@]option@|$$option|g" <$(srcdir)/egrep.sh >$@-t
       $(AM_V_at)chmod +x $@-t
       $(AM_V_at)mv $@-t $@

Generally I do believe that a) is easier and less risky change, but b)
feels to be more generic fix. (User may have GNU grep installed in /tmp
in which case /tmp/bin/egrep won't work unless you have /tmp/bin in your
PATH).

Comments welcome :)

Thank you
-- 
	Vlad