Skip to content

Instantly share code, notes, and snippets.

@dandean
Created February 7, 2013 17:46
Show Gist options
  • Select an option

  • Save dandean/4732706 to your computer and use it in GitHub Desktop.

Select an option

Save dandean/4732706 to your computer and use it in GitHub Desktop.
Check that a program exists before executing it in a shell script
# http://stackoverflow.com/questions/592620/check-if-a-program-exists-from-a-bash-script
command -v foo >/dev/null 2>&1 || { echo >&2 "I require foo but it's not installed. Aborting."; exit 1; }
type foo >/dev/null 2>&1 || { echo >&2 "I require foo but it's not installed. Aborting."; exit 1; }
hash foo 2>/dev/null || { echo >&2 "I require foo but it's not installed. Aborting."; exit 1; }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment