[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
affected.
Would the code below work on Solaris?
#!/bin/sh
dir=""
case $0 in
*/*) dir=${0%/*}/ 2>/dev/null
case $dir in
/ | "" ) dir=`dirname "$0"`
test "x$dir" != x && dir=$dir/
;;
esac
esac
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
- [bug-grep] egrep and fgrep script assume path, Joe Weening, 2005/01/26
- Re: [bug-grep] egrep and fgrep script assume path, Paul Jarc, 2005/01/27
- Re: [bug-grep] egrep and fgrep script assume path, Stepan Kasal, 2005/01/26
- Re: [bug-grep] egrep and fgrep script assume path, Paul Jarc, 2005/01/27
- Re: [bug-grep] egrep and fgrep script assume path,
Stepan Kasal <=
- Re: [bug-grep] egrep and fgrep script assume path, Paul Jarc, 2005/01/27
- Re: [bug-grep] egrep and fgrep script assume path, Stepan Kasal, 2005/01/27
- Re: [bug-grep] egrep and fgrep script assume path, Paul Jarc, 2005/01/27
- Re: [bug-grep] egrep and fgrep script assume path, Stepan Kasal, 2005/01/27
- Re: [bug-grep] egrep and fgrep script assume path, Paul Eggert, 2005/01/27
- Re: [bug-grep] egrep and fgrep script assume path, Stepan Kasal, 2005/01/28
- Re: [bug-grep] egrep and fgrep script assume path, Paul Eggert, 2005/01/29
- Re: [bug-grep] egrep and fgrep script assume path, Stepan Kasal, 2005/01/29
- Re: [bug-grep] egrep and fgrep script assume path, Paul Eggert, 2005/01/31