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

From: Anselm R. Garbe <arg_AT_suckless.org>
Date: Sun, 9 Dec 2007 11:07:09 +0100

On Sat, Dec 08, 2007 at 09:48:57PM +0100, Rickard Gustafsson wrote:
> That's a pretty nasty solution if you ask me. I would have used:
> if [ ! -f `which convert` ]

Both, type(1) and which(1) are not POSIX compliant and might be absent.
Though I'd use which(1) if you don't want to go the way used by
dmenu_path for instance.

Regards,
        Anselm

>
> On [Sat 08.12.2007 21:40], markus schnalke wrote:
> >
> > Hoi community,
> >
> > I have a question that is a bit off topic, but I think you are the
> > right ones to ask.
> >
> > 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'?
> >
> > I want to cover most of the unixoid systems.
> > But I dont want to walk through $PATH.
> >
> >
> > meillo
> >
>

-- 
 Anselm R. Garbe >< http://www.suckless.org/ >< GPG key: 0D73F361
Received on Sun Dec 09 2007 - 11:07:09 UTC

This archive was generated by hypermail 2.2.0 : Sun Jul 13 2008 - 15:09:58 UTC