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

From: Paul Eggert <[email-masked]>
Date: Wed, 24 Jun 2015 11:43:39 -0700

Vladimir Marek wrote:
> $ PATH=/usr/bin gegrep
> grep: illegal option -- E

On recently-patched Solaris 10 with bleeding-edge GNU grep, I see the following 
instead:

   $ PATH=/usr/bin gegrep
   gegrep: not found

The above behavior is with /bin/sh, and with gegrep installed in some directory 
that is in my ordinary PATH but not in /usr/bin.

> 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 "$@"

Assuming you configure this way:

   ./configure --prefix=/my/dir --program-prefix=g

(which is how I did it), the egrep script in bleeding-edge grep (obtained from 
savannah via git) should be much simpler:

   #!/bin/bash
   exec ggrep -E "$@"

and this may fix your problem (though I admit I don't understand your problem). 
  The egrep script was simplified as part of the fix for Bug#19998; see:

http://bugs.gnu.org/19998#37

By the way, probably you know this already, but portable scripts should not use 
egrep or fgrep, as these two commands have been removed from POSIX.  They should 
use 'grep -E' and 'grep -F' instead.