[Top][All Lists]

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

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

From: Stepan Kasal
Subject: Re: [bug-grep] egrep and fgrep script assume path
Date: Thu, 27 Jan 2005 12:50:22 +0100
User-agent: Mutt/1.4.1i

Hi Paul,

On Wed, Jan 26, 2005 at 12:28:13PM -0500, Paul Jarc wrote:
> Stepan Kasal <address@hidden> wrote:
> > Autoconf manual warns that not all hosts have dirname, even though it
> > doesn't mention any OS.  This claim could be still true.
> sed, then?

no.  I don't want the script to spawn an extra shell on GNU systems.

So I want to use the advanced expansion trick if possible.

> $ echo ${0%/*}
> bad substitution
> $ 
> (Note there is no empty line; echo did not run at all.)

Thanks for telling me.

> You could probe to see if it's supported like this:
> if { : ${0%/*}; } 2> /dev/null; then ...
> but that test itself will spawn an extra process on some shells (due
> to redirections applied to a compound command), including Solaris
> /bin/sh.

I don't mind the slowdown; most GNU platforms have bash and won't be

Would the code below work on Solaris?

case $0 in
  */*)  dir=${0%/*}/ 2>/dev/null
        case $dir in
        / | "" ) dir=`dirname "$0"`
            test "x$dir" != x && dir=$dir/
exec "${dir}"grep -E ${1+"$@"}

I think the code
- uses advanced expansion if possible
- calls dirname otherwise
- prints an error message and leaves dir="" if dirname is not available
  (If we receive reports about this, we can add a sed solution.)

Have a nice day,
        Stepan Kasal

reply via email to

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