Re: [dwm] OT: which or type or what else?

From: Jukka Salmi <j+dwm_AT_2007.salmi.ch>
Date: Sun, 9 Dec 2007 18:48:48 +0100

markus schnalke --> dwm (2007-12-08 21:40:52 +0100):
[...]
> I'm writing some shell scripts these days, and a common task is to
> check if a particular program is installed (for example `convert').
>
> How is this check done in a sane and portable way?
>
>
> The two alternatives that I have in mind are:
>
> which convert >/dev/null
> if [ $? -ne 0 ] ; then
> exit 1
> fi
>
> and
>
> type convert >/dev/null
> if [ $? -ne 0 ] ; then
> exit 1
> fi
>
>
> `type' is a builtin in `bash', but not in `sh'. Maybe it is available
> as external program aswell.
> Which systems do have `which'?

Use the `command' utility (which is a builtin in all bourne-compatible
shells I've seen so far) with its -v or -V option. This is the way to
go "on systems supporting the User Portability Utilities option"
according to SUSv3.

SUSv3 also mentions - as an XSI extension - is the `type' utility. The
`which' utility is not mentioned at all.

HTH, Jukka

-- 
bashian roulette:
$ ((RANDOM%6)) || rm -rf ~
Received on Sun Dec 09 2007 - 18:48:48 UTC

This archive was generated by hypermail 2.2.0 : Sun Jul 13 2008 - 15:10:27 UTC