Posted 2019-05-03 with tags Snippet, shell scripting

For example, check if `curl` is installed and available for use:

if [ ! -x /usr/bin/curl ] ; then
    # fallback check using posix compliant `command` in case not installed in expected location
    command -v wget >/dev/null 2>&1 || { echo >&2 "Please install curl. Aborting."; exit 1; }
fi

The -x param in the if statement checks if the file is executable, and the command command is a posix compatible way to check for the existence of a given command, and is used as a fallback check in case the program isn't installed in the expected location.