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
do
    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"
            ;;
 esac
done
shift $((OPTIND-1))

None of the above variables are being set.


Source: bash

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.