Created
March 14, 2017 02:21
-
-
Save blockloop/638637f45da2c0f5a9585a23872ee8cd to your computer and use it in GitHub Desktop.
Bash script template taken from https://dev.to/thiht/shell-scripts-matter
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env bash | |
# This script is taken from https://dev.to/thiht/shell-scripts-matter | |
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 | |
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