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.
Don't use
=
withgetopts
and short options. Also, if you want to supply "non-options", e.g. file names (video.mp4
in your case), they should come last, not before the options (and you have to change the code accordingly); or you can process them (andshift
) before you start the options loop.