Home πŸ‡ΊπŸ‡¦ Support Ukraine

Shell Script Bootstrap

Created: 2021-08-07

Reading time: 1 min


#!/bin/bash

PROG="${0##*/}"
VERSION="0.0.1"

err() {
    >&2 printf "Error: $1\n\n"
}

usg() {
>&2 cat << EOF
$PROG $VERSION
A bootstrap script.

USAGE:
    $PROG [OPTIONS]

OPTIONS:
    -h, --help                  Show this help.
    -t, --todo-long-option      Sample description.
EOF

    exit $1
}

[ "$#" -eq "0" ] && usg 1


OPT="$(getopt -oht -lhelp,todo-long-option -n"$PROG" -- "$@")"
eval set -- "$OPT"

while true; do
    case "$1" in
        -h|--help) usg 0 ;;
        -t|--todo-long-option) OPT_TODO=1; shift ;;
        --) shift; break ;;
        *) echo "Internal error!"; exit 1 ;;
    esac
done

[ -z "$OPT_TODO" ] || todo