Skip to content

Instantly share code, notes, and snippets.

@Programie
Last active March 8, 2022 18:04
Show Gist options
  • Select an option

  • Save Programie/389047751adf6a98a050 to your computer and use it in GitHub Desktop.

Select an option

Save Programie/389047751adf6a98a050 to your computer and use it in GitHub Desktop.
A simple function for Bash to require specific commands
#! /bin/bash
set -e
# This is a simply function to require a specific command
# The script will print an error message "Command x not found!" and exit if the command does not exist
function require()
{
which $1 > /dev/null 2>&1 || (echo "Command '$1' not found!"; exit 1)
}
# Example usage:
# require java
# require curl
# require scp
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment