ksh OPTARG Environment Variable

The OPTARG environment variable is set by the getopts Command when it parses an option with an argument. It contains the argument, but not the option letter. For example, if the positional arguments are:

-a -bfoo +c -de

and getopts is invoked as follows:

while getopts ab:cdef opt
do
        case $opt in
        a) aflag=on ;;
        b) bflag=$OPTARG ;;
        +c) cflag=off ;;
        c) cflag=on ;;
        d) dflag=on ;;
        e) eflag=on ;;
        f) fflag=on ;;
        esac
done

the resulting variable settings are:

aflag on
bflag foo
cflag off
dflag on
eflag on
fflag (no change)