getopts - Parse utility options

Synopsis

getopts optstring varname

Description

You can use getopts to check the positional parameters for legal options. An option argument begins with a minus (-). The end of the the options is marked by the first argument that does not begin with a minus or an argument of --.

Each time you call getopts, it places the next option letter it finds in varname. qsh stores the index of the next parameter to be processed in the variable OPTIND. When an option requires an argument, qsh stores the argument in the variable OPTARG.

Options

None.

Operands

The option letters recognized by getopts are identified in optstring. If a letter is followed by a colon (:), that option is expected to have an argument. The argument can be separated from the option letter by <space>s.

With each call to getopts, varname is updated with the option letter.

Exit Status