Glynn Clements wrote:
> > One minor point: I thought that using "which" was advised against,
> > as it isn't present on all platforms.
Hamish wrote:
> On what platforms is it missing? If `which` is missing, what are the
> chances that other assumed unix tools are missing? (ie everything
> breaks)
I don't know, but SUBMITTING_SCRIPTS says:
5. If you search for a command in $PATH, do NOT
use the "which" command or the "type -p" command. Both commands
are not supported on all platforms, thus causing problems for
some people. As an alternative, please use code similar to the
following shell script snippet which will perform the same
function. In this case, the path of the grass60 command is saved
if grass60 is found in $PATH. This won't recognize aliased
command name.
# Search for grass5 command in user's path
for i in `echo $PATH | sed 's/^:/.
s/::/:.:/g
s/:$/:./
s/ /g'`
do
if [ -f $i/grass5 ] ; then
# Save the path of the grass60 command
GRASS_PATH=$i/grass60
# Use the first one in user's path
break
fi
done
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.
fyi, I am responsible for adding this:
<?>
If you must use "which", use as follows:
# check if we have awk
if [ ! -x "`which awk`" ] ; then
echo "ERROR: awk required, please install awk or gawk first"
1>&2 exit 1
fi
</?>
> > If it is used, stderr should be redirected to /dev/null, to
> > silence the errors about x-terminal-emulator not being found.
>
> On what platforms does `which` not return silence if the target
> isn't found?
The GNU version isn't silent:
glynn@cerise:6.1 $ which foo
which: no foo in
(/opt/grass-6.3.cvs/bin:/opt/grass-6.3.cvs/scripts:<snip>)
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
I found these messages in the archives:
http://grass.itc.it/pipermail/grass-dev/2001-April/009332.html
(supposedly missing on Cray & Solaris*)
http://grass.itc.it/pipermail/grass-dev/2001-April/009280.html
http://grass.itc.it/pipermail/grass-dev/2001-April/009350.html
[*] `which` was apparently missing on Cray & Solaris, but I think that
the test used in that first email is incorrect. In fact on my linux:
$ alias which
bash: alias: which: not found
$ type -p which
/usr/bin/which
so which is there, just not an alias. I'm still not convinced the
problem actually exists.
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.
??,
Hamish