I'm having trouble wrapping my head around how to make getopts accept multiple flags with a single argument. For example.
Flags: Children: a - Adam b - Beth c - Cathy d - Duncan
Required parameter: ice cream flavor
(not what my script really does, but easiest to spell out this way)
What I can do right now:
./flavor -a chocolate ./flavor -c chocolate What I'd like to do:
./flavor -acd chocolate Rather than the only thing I can get it to do so far:
./flavor -a chocolate -c chocolate -d chocolate Every variation I've tried with getopts either doesn't see the parameter at all or requires it after every single flag declaration. I feel like I'm missing something obvious that will give me the "aha" moment, but I'm not seeing it on my own. Can anyone point me in the right direction?
============================================
while getopts ":a:b:c:d:" opt; do case $opt in a) do stuff with $OPTARG ;; b) do stuff with $OPTARG ;; c) do stuff with $OPTARG ;; d) do stuff with $OPTARG ;; :) echo "Option -$OPTARG requires an argument." >&2 exit 1 ;; esac done ============================================
My apologies if this is a really dumb question and thank you for your time.
./flavor -acda will consume cd as its$OPTARG.