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