Last active
February 26, 2021 01:12
-
-
Save nicksantamaria/ce2709fe81768966765c16e205796b6f to your computer and use it in GitHub Desktop.
Boilerplate bash script
This file contains 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 | |
set -euo pipefail | |
IFS=$'\n\t' | |
#/ Usage: | |
#/ Description: | |
#/ Examples: | |
#/ Options: | |
#/ --help: Display this help message | |
usage() { grep '^#/' "$0" | cut -c4- ; exit 0 ; } | |
expr "$*" : ".*--help" > /dev/null && usage | |
echoerr() { printf "%s\n" "$*" >&2 ; } | |
info() { echoerr "[INFO] $*" ; } | |
warning() { echoerr "[WARNING] $*" ; } | |
error() { echoerr "[ERROR] $*" ; } | |
fatal() { echoerr "[FATAL] $*" ; exit 1 ; } | |
cleanup() { | |
# Remove temporary files | |
# Restart services | |
info "... cleaned up" | |
} | |
if [[ "${BASH_SOURCE[0]}" = "$0" ]]; then | |
trap cleanup EXIT | |
# Script goes here | |
info "starting script ..." | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Adapted from https://dev.to/thiht/shell-scripts-matter