Skip to content

Instantly share code, notes, and snippets.

@simeg
Created August 26, 2017 16:10
Show Gist options
  • Save simeg/09ff64b291003d6835e4b4a9f1a15c79 to your computer and use it in GitHub Desktop.
Save simeg/09ff64b291003d6835e4b4a9f1a15c79 to your computer and use it in GitHub Desktop.
Bash function to see if executable is on $PATH
#!/bin/bash -e
# Example executables
readonly commands=(python git gitbook cp)
function is_available {
command -v $1 >/dev/null 2>&1 || { echo >&2 "I require $1 but it's not installed. Aborting."; exit 1; }
}
# Example usage (single)
is_available python;
# Example usage (all elements in array)
for cmd in ${commands[@]}; do is_available "$cmd"; done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment