[GRASS-dev] hardcoded 'xterm': wrapper?

Glynn Clements glynn at gclements.plus.com
Tue Aug 29 00:35:24 EDT 2006


Hamish wrote:

> Yes, I was aware of that, but was ignoring it as it has been many years
> since anyone reported an error with it and I never heard an explicit
> example of a platform where it wasn't present.

FWIW, "which" is normally a separate package, so it's possible that it
hasn't been installed even if it is available. But then the same is
true for sed, awk etc.

It isn't required by the Single Unix Specification, although "type" is
(but not the -p switch).

> ok, so how about this:
> 
> >       If you must use "which", use as follows:
> >   
> >   	# check if we have awk
> >   	if [ ! -x "`which awk 2> /dev/null`" ] ; then
> >   	    echo "ERROR: awk required, please install awk or gawk first"
> >   	    1>&2 exit 1
> >   	fi

That looks okay, although personally I wouldn't bother checking for
something as standard as awk.

> If we do need to use the `echo $PATH | sed..` method, I'd suggest
> writing it as a small script (returning 0 or 1) and moving it to
> $GISBASE/etc/ rather than cutting and pasting that ugly mess into
> all the scripts that need it.

We shouldn't ever actually need the full path to a program; if it's in
the path, we can just run it using its name. I'd be more inclined to
check for a program by using a test case. If the test fails, either
the program isn't present, or it doesn't work; we don't really need to
distinguish between the two.

E.g.:

	result=`awk 'BEGIN {print "working"}' 2>/dev/null`
	if [ $? != 0 -o "$result" != "working" ] ; then
		echo missing or broken \"awk\" >&2
		exit 1
	fi

-- 
Glynn Clements <glynn at gclements.plus.com>




More information about the grass-dev mailing list