getopts to use for both flags and option parsing

view story

http://stackoverflow.com – I am using getopts in my script and I want to work it for all the following order of option parsing. ./myscript -c server ./myscript -c -h server ./myscript server -c ./myscript -h server -c ./myscript server I am using myscript as follows. #!/bin/bash while getopts c:h: var do case $var in h) host=$OPTARG;; c) FLAG=1 esac done Here "server" is a argument and should load even -h option specifies or not and also -c option I am using for a FLAG.Is there a way to get this achieved. (HowTos)