Skip to content

Instantly share code, notes, and snippets.

@gorillamoe
Created March 16, 2017 14:27
Show Gist options
  • Save gorillamoe/34550ddadf3e28a7eb972c7d0a234645 to your computer and use it in GitHub Desktop.
Save gorillamoe/34550ddadf3e28a7eb972c7d0a234645 to your computer and use it in GitHub Desktop.
Sane Shell Scripting Skeleton
#!/usr/bin/env bash
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() {
echo "done cleanup"
}
add() {
local a=${1:-0}
local b=${2:-0}
echo $(( a + b ))
}
main() {
local dir=${1:-"/var/www"}
}
if [[ "${BASH_SOURCE[0]}" = "$0" ]]; then
trap cleanup EXIT
main "$@"
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment