title: Check if a command exists in Bash (including superusers)
body: <p>I'd like to check whether a program is installed on an UNIX system.</p>
  
  <p>I could use commands like:</p>
  
  <ul>
  <li><code>command -v</code>,</li>
  <li><code>hash</code>,</li>
  <li><code>type</code>,</li>
  <li><code>which</code>...</li>
  </ul>
  
  <p>...and all of them are already mentioned <a href="https://stackoverflow.com/questions/592620/check-if-a-program-exists-from-a-bash-script">in this answer</a>.</p>
  
  <p>However, none of them work if I want to test, <strong>as a normal user</strong>, whether I or <strong>any superuser</strong> can run given command.</p>
  
  <p>Here's an example of what I mean:</p>
  
  <pre><code>dummy:~$ command -v poweroff; echo $?
  1
  dummy:~$ su
  root:~# command -v poweroff; echo $?
  /sbin/poweroff
  0
  </code></pre>
  
  <p>As you see, normal user didn't find out about the existence of the <code>poweroff</code> command. Note that dummy users can freely see what's in <code>/sbin</code> anyway.</p>