Skip to content

Instantly share code, notes, and snippets.

@jacksonporter
Last active March 21, 2020 00:47
Show Gist options
  • Save jacksonporter/791145218e977ef9165abd9fdf8fbfd4 to your computer and use it in GitHub Desktop.
Save jacksonporter/791145218e977ef9165abd9fdf8fbfd4 to your computer and use it in GitHub Desktop.
A set of common bash script variables and functions to use within other bash scripts
#!/usr/bin/env bash
# Written by Jackson Porter
NO_COLOR='\033[0m'
GREEN_COLOR='\033[0;32m'
RED_COLOR='\033[0;31m'
YELLOW_COLOR='\033[1;33m'
function check_if_root {
if [[ ${EUID} -ne 0 ]]; then
printf "${RED_COLOR}This script must be run as root!${NO_COLOR}\n"
exit 1
fi
}
function print_with_color {
printf "${1}${2}${NO_COLOR}\n"
}
function print_warning {
print_with_color ${YELLOW_COLOR} "${1}"
}
function print_error {
print_with_color ${RED_COLOR} "${1}"
}
function print_success {
print_with_color ${GREEN_COLOR} "${1}"
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment