I strongly suggest using something like getopts when parsing command line arguments. When you use getopts to process options, you get the same capabilities all of the standard utilities use when parsing options: single-character options without option-arguments can be grouped behind a single minus sign or each can follow separate minus signs, options with option-arguments can be combined in a single operand or be presented as separate arguments, -- can be used to end option processing so following operands can start with a minus sign and not be mistaken for options, the order of options won't matter, etc.
From your example, it appeared that you code script could be invoked as: ./script , ./script -k , or ./script -f file . The following can be invoked with no options, with -k or -f file , or with both -k and -f file in any order. When the -f option is given, this script gives an error if the option argument is not a regular file. if you call this script with options other than -f and -k, it will tell you that it found an option it didn't expect. It also tells you how many operands are left after the options are processed and prints them.
Hope this helps:
#!/bin/ksh
IAm=${0##*/}
err=0
File=""
kflag=
while getopts f:k opt
do case $opt in
(f) File="$OPTARG"
if [ ! -f "$File" ]
then printf "Option -f \"%s\": Not a regular file\n" "$File" >&2
err=1
fi;;
(k) kflag=1;;
(?) err=2;;
esac
done
shift $(($OPTIND - 1))
if [ $err -gt 0 ]
then printf "Usage: %s: [-k] [-f pathname] arg...\n" "$IAm" >&2
exit $err
fi
if [ "$kflag" ]
then printf "Option k found\n"
fi
if [ -n "$File" ]
then printf "Option -f \"%s\" found; argument is a regular file\n" "$File"
fi
if [ $# -gt 0 ]
then printf "%d remaining operands are:" $#
printf " %s" "$*"
echo
else echo "No operands found."
fi