Bash - Check if command is available / installed

Ever wanted to check if a command is available in bash, before just assuming it is installed?

This comes in handy if you write custom install scripts and what not (stuff that I'm doing on a some-what daily-basis).

Just check if a program is available on the target system and if it's not installed (yet), just exit with a nice error message that informs the user that you rely on app xy to be installed.

function __command_exists {
    local exists=$(command -v "$1")
    # command does not exist
    if [[ -z $exists ]]; then
        echo 0
    else # command exists
        echo 1
    fi
}
if [[ $(__command_exists "xsltproc") -eq 0 ]]; then
    echo "xsltproc package is required"
    exit 1
fi