Bash

February 26, 2019

getopt

my-function() {
    # This is important for getopt or it will fail on the second invocation!
    local OPTIND
    while getopts 'u:b:s:' _flag
    do
        echo "_flag=$_flag"
        case "${_flag}" in
            u) GIT_URL="$OPTARG" ;;
            b) GIT_BRANCH="-b $OPTARG" ;;
            s) SPEC+="$OPTARG " ;;
            *) echo "my-function(): Unexpected option $_flag"; exit 1; ;;
        esac
    done
}