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



Reply via email to