Skip to content

Instantly share code, notes, and snippets.

@nicksantamaria
Last active February 26, 2021 01:12
Show Gist options
  • Save nicksantamaria/ce2709fe81768966765c16e205796b6f to your computer and use it in GitHub Desktop.
Save nicksantamaria/ce2709fe81768966765c16e205796b6f to your computer and use it in GitHub Desktop.
Boilerplate bash script
#!/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
@nicksantamaria
Copy link
Author

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment