Skip to content

Instantly share code, notes, and snippets.

@qinshulei
Last active August 29, 2015 14:05
Show Gist options
  • Save qinshulei/d5b25f437ed46aaeb9a9 to your computer and use it in GitHub Desktop.
Save qinshulei/d5b25f437ed46aaeb9a9 to your computer and use it in GitHub Desktop.
check if command exists
# 1. use command -v
command -v foo >/dev/null 2>&1 || { echo >&2 "I require foo but it's not installed. Aborting."; exit 1; }
# 2. use type .
if ! type "$foobar_command_name" > /dev/null; then
# install foobar here
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment