Skip to content

Instantly share code, notes, and snippets.

@diegoholiveira
Created May 26, 2018 20:02
Show Gist options
  • Save diegoholiveira/bf48c3aafb618af536c6acc053161358 to your computer and use it in GitHub Desktop.
Save diegoholiveira/bf48c3aafb618af536c6acc053161358 to your computer and use it in GitHub Desktop.
a template for bash scripts
#!/usr/bin/env bash
# source: https://dev.to/thiht/shell-scripts-matter
set -euo pipefail
IFS=$'\n\t'
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() {
# ...
}
trap cleanup EXIT
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment