bug-grep
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: grep-2.5.1a egrep/fgrep PATH problem


From: Charles Levert
Subject: Re: grep-2.5.1a egrep/fgrep PATH problem
Date: Thu, 23 Jun 2005 21:17:23 -0400
User-agent: Mutt/1.4.1i

Thanks for taking the time to look at this.

* On Thursday 2005-06-23 at 17:04:29 -0700, Paul Eggert wrote:
> Charles Levert <address@hidden> writes:
> 
> > What do others on the list think?
> 
> We should go back to the way "grep" used to do this, before we broke it.
> That is, we should use binaries by default.
> 
> I am partly responsible for this, because I introduced the wrappers
> in the first place.  Sorry about that.
> 
> Can you please let me undo the damage I caused?  That is, how about if
> you grant me write access to the grep repository, and let me install
> the following change to revert to the old behavior.  We can improve on
> this later if need be (e.g., by adding an installation-time option to
> do non-conforming installations), but our first item of business ought
> to be to conform to the GNU coding standards, and this patch does that.

As your message was finding its way to my
mailbox, I have been investigating this as well
and also have something to propose.  I will
study your solution after I send this email.

I don't have the priviledges to grant write
access to CVS; Stepan is the one who does.
I do however have write access myself, so I can
readily commit your changes while keeping your
name in the ChangeLog.

Since this is touchy, I'll wait a while and let
others have a chance to weigh in before doing
anything right away.

In the mean time, here's a description of what
I've been working on.  This solution has these
features:

   -- It's still a shell script solution (so
      it does avoid the size of having several
      binaries).

   -- It uses "test -f", which will either
      pick up a test shell builtin, or a
      test program in the PATH, but it has to
      be there somewhere.

   -- It avoids "test -x", since it's documented
      by autoconf.info as being non-portable.

   -- It avoids "test -r", since a binary could
      still be executable without being readable
      (e.g., 711, but who would do that with
      grep!?).

   -- It makes sure the shell script is readable
      by all, otherwise it can't be executed
      (not being a binary).

   -- It adds as many double quotes as is
      portable, just to be prudent about
      embedded spaces (but it may not be enough;
      who would put spaces in _system_ paths or
      executables anyway!?).  The problem is that
      "`cmd ""`" is not a portable equivalent of
      "$(cmd "")".

   -- It makes sure $(transform) is used.

   -- It first looks in the same directory as
      specified by the invocation path, if any,
      then in $(bindir), and only otherwise lets
      the PATH lookup mechanism do its work.

   -- If the shell doesn't support
      %-parameter-substitution, a variable
      named 0%/* will be looked-up and will
      most likely be undefined (thus empty)
      and that will be detected.

   -- It may not work if for some reason ones
      copies {,f,e}grep in / (root directory).

Here it is.  The following rule in
src/Makefile.am

vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv
egrep fgrep: Makefile
        (echo '#! /bin/sh'; \
        echo 'p="'`echo grep|sed '$(transform)'`'"' ; \
        echo 'case "$$0" in' ; \
        echo '  */*)' ; \
        echo '    d="$${0%/*}/"' ; \
        echo '    if test "x$$d" != x/ && test -f "$$d$$p"; then :; else' ; \
        echo '      d="'$(bindir)'/"' ; \
        echo '      if test -f "$$d$$p"; then :; else' ; \
        echo '        d=""' ; \
        echo '      fi' ; \
        echo '    fi' ; \
        echo '    ;;' ; \
        echo '  *)' ; \
        echo '    d="'$(bindir)'/"' ; \
        echo '    if test -f "$$d$$p"; then :; else' ; \
        echo '      d=""' ; \
        echo '    fi' ; \
        echo '    ;;' ; \
        echo 'esac' ; \
        echo 'exec "$$d$$p" $(OPTION_for_$@) $${1+"$$@"}' ) >$@
        chmod a+rx $@
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

produces on a default install for egrep:

vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv
#! /bin/sh
p="grep"
case "$0" in
  */*)
    d="${0%/*}/"
    if test "x$d" != x/ && test -f "$d$p"; then :; else
      d="/usr/local/bin/"
      if test -f "$d$p"; then :; else
        d=""
      fi
    fi
    ;;
  *)
    d="/usr/local/bin/"
    if test -f "$d$p"; then :; else
      d=""
    fi
    ;;
esac
exec "$d$p" -E ${1+"$@"}
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^




reply via email to

[Prev in Thread] Current Thread [Next in Thread]