Bash template script - change line end character
This commit is contained in:
29
scripts/bash-template.sh
Normal file → Executable file
29
scripts/bash-template.sh
Normal file → Executable file
@@ -1,17 +1,22 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
# !! DRAFT !!
|
||||
|
||||
# https://betterdev.blog/minimal-safe-bash-script-template/
|
||||
# https://medium.com/better-programming/my-minimal-safe-bash-script-template-300759114040
|
||||
# https://github.com/koalaman/shellcheck
|
||||
|
||||
|
||||
set -E -o errexit -o nounset -o pipefail
|
||||
trap cleanup SIGINT SIGTERM ERR EXIT
|
||||
|
||||
readonly SCRIPT_NAME=$(basename "${BASH_SOURCE[0]}")
|
||||
readonly SCRIPT_DIR=$(cd "$(dirname "${BASH_SOURCE[0]}")" &>/dev/null && pwd -P)
|
||||
readonly ERROR_CODE=90
|
||||
|
||||
function usage() {
|
||||
cat <<EOT
|
||||
Usage: ${script_name} [-h | --help] [-a <ARG>] [--abc <ARG>] [-f | --flag]
|
||||
cat <<-EOT
|
||||
Usage: ${SCRIPT_NAME} [-h | --help] [-a <ARG>] [--abc <ARG>] [-f | --flag]
|
||||
DESCRIPTION
|
||||
Your description here.
|
||||
OPTIONS:
|
||||
@@ -36,18 +41,17 @@ function msg() {
|
||||
}
|
||||
|
||||
function die() {
|
||||
local -r msg="$1"
|
||||
local -r code="${2:-90}"
|
||||
echo "${msg}" >&2
|
||||
exit "${code}"
|
||||
local msg="$1"
|
||||
local code="${2:-$ERROR_CODE}"
|
||||
echo "$msg" >&2
|
||||
exit "$code"
|
||||
}
|
||||
|
||||
function parse_params() {
|
||||
local -r args=("${@}")
|
||||
local EXTRA_ARGS=()
|
||||
|
||||
while true; do
|
||||
|
||||
case "$1" in
|
||||
for ARG in "$@"; do
|
||||
case "$ARG" in
|
||||
--abc)
|
||||
abc_option_flag=1
|
||||
shift
|
||||
@@ -79,10 +83,13 @@ function parse_params() {
|
||||
;;
|
||||
|
||||
*)
|
||||
break
|
||||
EXTRA_ARGS+=("$opt")
|
||||
;;
|
||||
|
||||
esac
|
||||
done
|
||||
|
||||
# join EXTRA_ARGS a ARGS
|
||||
}
|
||||
|
||||
# MAIN
|
||||
|
||||
Reference in New Issue
Block a user