Last active
October 11, 2023 12:35
-
-
Save nouredd2/cb7956fe5d4b22941beac723e6655a5a to your computer and use it in GitHub Desktop.
Header for my bash scripts.
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
#!/usr/bin/env bash | |
# <script_name> v1.0 | |
# | |
# <TODO: Add script description.> | |
# | |
# Author: Mohammad Noureddine <[email protected]> | |
# Late modified: | |
# | |
VERSION_NUMBER="1.0" | |
VERSION_DATE="August 2023" | |
# config variables | |
# color variables | |
RED='\033[1;31m' # red | |
YELLOW='\033[1;33m' # yellow | |
GREEN='\033[1;32m' # green | |
RESET='\033[0m' # no color | |
# Print a warning for the user. | |
# | |
# @param First argument is the warning message to print to the user. | |
# | |
print_warning() { | |
echo -n -e "$YELLOW" | |
echo -e "[WARNING] $1" | |
echo -n -e "$RESET" | |
} | |
# Print an error message for the user | |
# | |
# @param First argument is the error message to print to the user. | |
# | |
print_error() { | |
echo -n -e "$RED" | |
echo -e "[ERROR] $1" | |
echo -n -e "$RESET" | |
} | |
# Print a log for the user. | |
# | |
# @param First argument is the log message to print to the user. | |
# | |
print_log() { | |
echo -n -e "$GREEN" | |
echo -e "$1" | |
echo -n -e "$RESET" | |
} | |
# Print the usage description for this program, usually program exits after | |
# this. | |
# | |
print_usage() { | |
echo -e "usage: $0 [-h] [-V]" | |
echo -e '' | |
echo -e '<TODO: Add script description.>' | |
echo -e '' | |
echo -e 'options:' | |
echo -e '-h Show this help message and exit.' | |
echo -e '-V Print version number and exit.' | |
} | |
# Print the version of this program, usually program exits after this. | |
print_version() { | |
echo -e "$0 version $VERSION_NUMBER of $VERSION_DATE" | |
} | |
# parse command line arguments | |
while getopts ":hV" arg; do | |
case $arg in | |
V) | |
print_version | |
exit 0 | |
;; | |
h | *) | |
print_usage | |
exit 0 | |
;; | |
esac | |
done | |
shift $((OPTIND-1)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment