Skip to content

Instantly share code, notes, and snippets.

@kitop
Created March 31, 2017 07:39
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kitop/1bbc00254787cbf5bd97249b7d1e5489 to your computer and use it in GitHub Desktop.
Save kitop/1bbc00254787cbf5bd97249b7d1e5489 to your computer and use it in GitHub Desktop.
Template Bash Script
#!/usr/bin/env bash
set -euo pipefail
IFS=$'\n\t'
# Taken from https://dev.to/thiht/shell-scripts-matter
#/ Usage:
#/ Description:
#/ Examples:
#/ Options:
#/ --help: Display this help message
usage() { grep '^#/' "$0" | cut -c4- ; exit 0 ; }
expr "$*" : ".*--help" > /dev/null && usage
readonly LOG_FILE="/tmp/$(basename "$0").log"
info() { echo "[INFO] $@" | tee -a "$LOG_FILE" >&2 ; }
warning() { echo "[WARNING] $@" | tee -a "$LOG_FILE" >&2 ; }
error() { echo "[ERROR] $@" | tee -a "$LOG_FILE" >&2 ; }
fatal() { echo "[FATAL] $@" | tee -a "$LOG_FILE" >&2 ; exit 1 ; }
cleanup() {
# Remove temporary files
# Restart services
# ...
}
if [[ "${BASH_SOURCE[0]}" = "$0" ]]; then
trap cleanup EXIT
# Script goes here
# ...
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment