[フレーム]
Last Updated: July 12, 2017
·
3.623K
· fr0gs

Basic script template for every bash script

All credits to this post

#!/usr/bin/env bash
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
 # ...
}

# Parse Parameters #
while [ "$#" -gt 1 ];
 do
 key="1ドル"

 case $key in
 -d|--discovery)
 discovery_period="2ドル" # EXAMPLE
 shift
 ;;
 --default)
 default=YES
 ;;
 *)
 ;;
 esac
 shift
done

if [[ "${BASH_SOURCE[0]}" = "0ドル" ]]; then
 trap cleanup EXIT
 # Script goes here
 # ...
fi

AltStyle によって変換されたページ (->オリジナル) /