OPTIND

The variable getopts uses to track which argument it will read next; after the loop it points at the first operand.

In more detail

getopts starts it at 1 and moves it past each option it reads. shift "$((OPTIND - 1))" after the loop removes every option, leaving the operands in $1, $2 and $@.

Related terms

Taught in

References