Subject: Re: Strange shell problem
To: None <netbsd-help@netbsd.org>
From: Russell McManus <russell_mcmanus@yahoo.com>
List: netbsd-help
Date: 11/18/2002 11:24:43
Instead of:

  [ -x notaprogram ]

you can use:

  test -x notaprogram >/dev/null 2>&1

-russ


Chris Lloyd <strawberry@toth.org.uk> writes:

> I'm having a problem with a bit of shell script, the problem only seems to
> exhibit itself on NetBSD.
> 
> where=`which notaprogram`; if [ $? -gt 0 ]; then echo "Install it"; fi
> 
> I'm trying to work out if an executable exists, to be used later on in the
> script, and warn the user if they haven't got it installed.
> 
> Problem is, on my netbsd machine, $? seems to be being set to 0 by which.
> It doesn't get set to 0 on linux or openbsd. Is being set to 0 the correct
> behaviour or not?
> 
> If anyone knows a nicer way of checking to see if a program exists, then 
> that'd be good too. (I don't really want to use if [ -x notaprogram ] because
> that prints on the shells stderr in an ugly way.
> 
> Thanks, 
> 
>  - Chris
> 
> --
> strawberry@toth.org.uk
> http://www.toth.org.uk/~strawberry