I've been frustrated before with differences in output from the which
command across different platforms (Linux vs. Solaris vx. OS X), with different shells possibly playing into the matter as well. type
has been suggested as a better alternative, but how portable would that be?
In the past I've written functions which parse the output of which
and handle the different use cases I've run into. They work across the machines I use, and so are okay for my personal scripts, but this seems terribly unreliable for software that I'm going to post somewhere for others to use.
To take just one possible example, suppose I have to detect from a script whether bash and zsh are available on a machine, and then run a command with zsh if it is present, and with bash if zsh is not and bash is of a sufficient version to not have a particular bug. Most of the rest of the script could be Bourne shell or Ruby or anything else, but this one particular thing must be done (AFAIK) with either zsh or a recent version of bash.
Can I count on type
being available across platforms? Is there some other alternative to which
which can easily and consistently answer the question of whether a particular piece of software is installed?
(If you want to also give ideas specifically related to the example I gave, that's great, but I'm mainly just asking about the general case: what is the most reliable way to find out if a particular thing is installed on a given machine?)