Check if Program Installed within Shell Script


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.



Comments:


Gravatar of Kyle Jones

Knowledge Base is a repository for various notes, guides, and thoughts on a wide range of IT related topics. Read more...

Sponsored By:


Web development services by Say Web Solutions. Visit website.