bug-grep
[Top][All Lists]
Advanced

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

Re: [bug-grep] egrep and fgrep script assume path


From: Paul Eggert
Subject: Re: [bug-grep] egrep and fgrep script assume path
Date: Wed, 26 Jan 2005 16:08:21 -0800
User-agent: Gnus/5.1006 (Gnus v5.10.6) Emacs/21.3 (gnu/linux)

Stepan Kasal <address@hidden> writes:

> the egrep script now looks like this:
>
> #!/bin/sh
> case $0 in
>   */*) dir=${0%/*}/ ;;
>   *) dir="" ;;
> esac
> exec ${dir}grep -E ${1+"$@"}

The "%/*" isn't portable, but more importantly the script doesn't
conform to the GNU coding standards, which say this:

  Please don't make the behavior of a utility depend on the name used
  to invoke it. It is useful sometimes to make a link to a utility
  with a different name, and that should not change what it does.

  <http://www.gnu.org/prep/standards/html_node/User-Interfaces.html>

With the script as quoted above, one cannot make a link to (or copy
of) egrep and expect it to work.  For example, this common tactic
won't work any more:

  mkdir $HOME/bin
  cp /usr/local/bin/egrep $HOME/bin
  export PATH=$HOME/bin:$PATH
  egrep foo bar

as the result will be something like this:

  /home/eggert/bin/egrep: /home/eggert/bin/grep: No such file or directory

Here is a patch.

2005-01-26  Paul Eggert  <address@hidden>

        * src/Makefile.am (egrep fgrep): Don't assume that grep is
        adjacent; the GNU coding standards say that you should be
        able to copy egrep without necessarily copying grep.

Index: src/Makefile.am
===================================================================
RCS file: /cvsroot/grep/grep/src/Makefile.am,v
retrieving revision 1.32
diff -p -u -r1.32 Makefile.am
--- src/Makefile.am     23 Nov 2004 12:49:36 -0000      1.32
+++ src/Makefile.am     27 Jan 2005 00:03:10 -0000
@@ -24,9 +24,5 @@ OPTION_for_fgrep = -F
 
 egrep fgrep: Makefile
        (echo '#!/bin/sh'; \
-       echo 'case $$0 in' ; \
-       echo '  */*) dir=$${0%/*}/ ;;' ; \
-       echo '  *) dir="" ;;' ; \
-       echo 'esac' ; \
-       echo 'exec $${dir}grep $(OPTION_for_$@) $${1+"$$@"}' ) >$@
+       echo 'exec '\''$(bindir)/grep'\'' $(OPTION_for_$@) $${1+"$$@"}' ) >$@
        chmod a+x $@




reply via email to

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