Posted By

jeremydouglass on 04/25/11


Tagged

command check test Bash


Versions (?)

if command exists (Bash)


 / Published in: Bash
 

URL: http://www.cyberciti.biz/faq/unix-linux-shell-find-out-posixcommand-exists-or-not/

  1. #!/bin/bash
  2. # POSIX command lookup example
  3. CMDS="tar /usr/bin/mysqldump /path/to/other/command"
  4. for i in $CMDS
  5. do
  6. # command -v will return >0 when the $i is not found
  7. command -v $i >/dev/null && continue || { echo "$i command not found."; exit 1; }
  8. done

Report this snippet  

You need to login to post a comment.