Skip to content

Instantly share code, notes, and snippets.

@fwal
Created October 22, 2014 07:30
Show Gist options
  • Save fwal/a52575313f75e1bdc86f to your computer and use it in GitHub Desktop.
Save fwal/a52575313f75e1bdc86f to your computer and use it in GitHub Desktop.
Simple script for checking if certain commands are installed and prompt the user to install them if not
#! /bin/bash
function prompt {
while true; do
read -p "$1 is not installed. Do you wish to install it? [y/n]:" yn
case $yn in
[Yy]* ) return 1;;
[Nn]* ) return 0;;
* ) echo "Please answer yes or no.";;
esac
done
}
function check {
command -v $1 >/dev/null 2>&1 || {
if prompt "$2" $1;
then echo "Aborting...";
else $3;
fi
}
}
# Syntax: check command display_name install_command
check /bin/foo "Foo" "echo Executing some install command :)"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment