Created
August 26, 2017 16:10
-
-
Save simeg/09ff64b291003d6835e4b4a9f1a15c79 to your computer and use it in GitHub Desktop.
Bash function to see if executable is on $PATH
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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