Getopts loop not working

I am working on a bash script, and I decided to use getopts to get the options, but the loop I used doesn’t work! Could someone please help me?

while getopts "u:p:k:s:t:c:l:" flag
    echo $flag
    case "$flag" in
        k)  APIKEY="$OPTARG"
        s)  APISECRET="$OPTARG"
        u)  USERNAME="$OPTARG"
        p)  PASSWORD="$OPTARG"
        t)  TITLE="$OPTARG"
        c)  CATEGORY="$OPTARG"
        l)  LANGUAGE="$OPTARG"
shift $((OPTIND-1))

None of the above variables are being set.

Source: bash

Leave a Reply