GNU bug report logs - #20883
egrep on Solaris fails to call original grep binary

Previous Next

Package: grep;

Reported by: Vladimir Marek <Vladimir.Marek <at> oracle.com>

Date: Tue, 23 Jun 2015 15:40:02 UTC

Severity: normal

Done: Paul Eggert <eggert <at> cs.ucla.edu>

Bug is archived. No further changes may be made.

To add a comment to this bug, you must first unarchive it, by sending
a message to control AT debbugs.gnu.org, with unarchive 20883 in the body.
You can then email your comments to 20883 AT debbugs.gnu.org in the normal way.

Toggle the display of automated, internal messages from the tracker.

View this report as an mbox folder, status mbox, maintainer mbox


Report forwarded to bug-grep <at> gnu.org:
bug#20883; Package grep. (Tue, 23 Jun 2015 15:40:03 GMT) Full text and rfc822 format available.

Acknowledgement sent to Vladimir Marek <Vladimir.Marek <at> oracle.com>:
New bug report received and forwarded. Copy sent to bug-grep <at> gnu.org. (Tue, 23 Jun 2015 15:40:03 GMT) Full text and rfc822 format available.

Message #5 received at submit <at> debbugs.gnu.org (full text, mbox):

From: Vladimir Marek <Vladimir.Marek <at> oracle.com>
To: bug-grep <at> gnu.org
Subject: egrep on Solaris fails to call original grep binary
Date: Tue, 23 Jun 2015 17:39:15 +0200
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




Information forwarded to bug-grep <at> gnu.org:
bug#20883; Package grep. (Wed, 24 Jun 2015 18:44:02 GMT) Full text and rfc822 format available.

Message #8 received at 20883 <at> debbugs.gnu.org (full text, mbox):

From: Paul Eggert <eggert <at> cs.ucla.edu>
To: Vladimir Marek <Vladimir.Marek <at> oracle.com>, 20883 <at> debbugs.gnu.org
Subject: Re: bug#20883: egrep on Solaris fails to call original grep binary
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.




Information forwarded to bug-grep <at> gnu.org:
bug#20883; Package grep. (Fri, 26 Jun 2015 15:10:03 GMT) Full text and rfc822 format available.

Message #11 received at 20883 <at> debbugs.gnu.org (full text, mbox):

From: Vladimir Marek <Vladimir.Marek <at> oracle.com>
To: Paul Eggert <eggert <at> cs.ucla.edu>
Cc: 20883 <at> debbugs.gnu.org
Subject: Re: bug#20883: egrep on Solaris fails to call original grep binary
Date: Fri, 26 Jun 2015 17:09:34 +0200
> >$ 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 "$@"


That's a nice simplification of the previous state :)


> 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.

Thank you for the pointer, it helps. Also sorry for the not-so-clear
report, after thinking about it twice, the problem in Solaris is that we
provide both variants. With 'g' prepended and without. So I have to make
the script a little bit more difficult.


Thanks for your time looking at this and your help

-- 
	Vlad




Reply sent to Paul Eggert <eggert <at> cs.ucla.edu>:
You have taken responsibility. (Fri, 26 Jun 2015 20:41:03 GMT) Full text and rfc822 format available.

Notification sent to Vladimir Marek <Vladimir.Marek <at> oracle.com>:
bug acknowledged by developer. (Fri, 26 Jun 2015 20:41:04 GMT) Full text and rfc822 format available.

Message #16 received at 20883-done <at> debbugs.gnu.org (full text, mbox):

From: Paul Eggert <eggert <at> cs.ucla.edu>
To: Vladimir Marek <Vladimir.Marek <at> oracle.com>
Cc: 20883-done <at> debbugs.gnu.org
Subject: Re: bug#20883: egrep on Solaris fails to call original grep binary
Date: Fri, 26 Jun 2015 13:40:03 -0700
Thanks for following up; sounds like grep is OK then, so closing the bug.




bug archived. Request was from Debbugs Internal Request <help-debbugs <at> gnu.org> to internal_control <at> debbugs.gnu.org. (Sat, 25 Jul 2015 11:24:04 GMT) Full text and rfc822 format available.

This bug report was last modified 9 years and 334 days ago.

Previous Next


GNU bug tracking system
Copyright (C) 1999 Darren O. Benham, 1997,2003 nCipher Corporation Ltd, 1994-97 Ian Jackson.