Last active
March 8, 2022 18:04
-
-
Save Programie/389047751adf6a98a050 to your computer and use it in GitHub Desktop.
A simple function for Bash to require specific commands
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #! /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