title: Find out if a command exists on POSIX system
body: <p>I want to be able to tell if a command exists on any POSIX system from a shell script.</p>
  
  <p>On Linux, I can do the following:</p>
  
  <pre><code>if which &lt;command&gt;; then
     ...snip...
  fi
  </code></pre>
  
  <p>However, Solaris and MacOS <code>which</code> do not give an exit failure code when the command does not exist, they just print an error message to STDOUT.</p>
  
  <p>Also, I recently discovered that the <code>which</code> command itself is not POSIX (see <a href="http://pubs.opengroup.org/onlinepubs/9699919799/idx/utilities.html" rel="noreferrer">http://pubs.opengroup.org/onlinepubs/9699919799/idx/utilities.html</a>)</p>
  
  <p>Any ideas?</p>