../𝚂𝚃𝚇
source

tl;dr shell getopts

Published 2020-01-16, last edit 2020-01-23

# the ':' in front means the flag takes an arg
while getopts w:reh flag; do
    case $flag in
        w) wid=$OPTARG;;
        r) some_thing;;
        e) print_env;;
        h) usage;;
        *) usage;;
    esac
done

# this shift at the end is to reset the args to the env of getopts parsing
shift $((OPTIND-1))