Linux shell/Skeletons

From Ever changing code
< Linux shell
Revision as of 16:05, 16 February 2020 by Pio2pio (talk | contribs) (Created page with "= Option based = <source lang=bash> #!/usr/bin/env bash set -o pipefail set -o nounset set -o errexit err_report() { echo "Exited with error on line $1" } trap 'err_repo...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

Option based

#!/usr/bin/env bash

set -o pipefail
set -o nounset
set -o errexit

err_report() {
    echo "Exited with error on line $1"
}
trap 'err_report $LINENO' ERR

IFS=$'\n\t'

function print_help {
    echo "usage: $0 [options] <arg1>"
    echo "Bootstraps an instance into an EKS cluster"
    echo ""
    echo "-h,--help print this help"
    echo "--option1-max Sets max XX (default: true)"
}

POSITIONAL=()

while [[ $# -gt 0 ]]; do
    key="$1"
    case $key in
        -h|--help)
            print_help
            exit 1
            ;;
        --option1-max)
            OPTION1_MAX="$2"
            shift; shift
            ;;
        *)    # unknown option
            POSITIONAL+=("$1") # save it in an array for later
            shift # past argument
            ;;
    esac
done

set +u
set -- "${POSITIONAL[@]}" # restore positional parameters
ARG1="$1" # positional argument 1
set -u

# Defaults
OPTION1_MAX="${OPTION1_MAX:-true}"

# Functions
function get_ready () {
    local ready="$1"
}

# Main
true