if command exists (Bash)


/ Published in: Bash
Save to your folder(s)



Copy this code and paste it in your HTML
  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

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

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.