Skip to content

Instantly share code, notes, and snippets.

@matthewmccullough
Created June 29, 2011 16:55
Show Gist options
  • Select an option

  • Save matthewmccullough/1054304 to your computer and use it in GitHub Desktop.

Select an option

Save matthewmccullough/1054304 to your computer and use it in GitHub Desktop.
Tests if an app is installed. Response code could be checked by an if-test
#!/bin/bash
#Ensure we have one argument specified on the CLI
if [ -z "$1" ]; then ARG_ERR=ERR; fi
if [ -n "$ARG_ERR" ];
then
echo "Checks if an app (passed as a parameter) is installed/reachable"
echo " on this machine by using the 'hash' command."
echo "Usage: isappinstalled <appname>"
echo "Returns: 0 if is installed, 1 if not installed."
exit
fi
hash $1 2>&- || { echo >&2 "I require $1 but it's not installed."; exit 1; }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment