Strict Mode Bash Script Skeleton
Start scripts with strict mode settings so unset variables, failing commands, and pipe errors stop execution instead of being silently ignored.
Code
#!/usr/bin/env bash
set -euo pipefail
IFS=$'\n\t'
readonly SCRIPT_DIR="$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" && pwd)"
log() {
printf '%s [%s] %s\n' "$(date -u +%Y-%m-%dT%H:%M:%SZ)" "$1" "$2"
}
if [[ $# -lt 1 ]]; then
log ERROR "usage: $(basename "$0") <target>"
exit 64
fi
log INFO "starting against $1"
"${SCRIPT_DIR}/process.sh" "$1"Report a problem with this exampleOpens a pre-filled issue on GitHub.