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
- getopts — The builtin that parses short command-line options such as -v, -vq and -f value, one option per call, in a while loop.
- OPTARG — The variable getopts fills with the value of an option that takes one, such as the file name after -f.
- shift builtin — The builtin that drops $1 and moves every remaining positional parameter down by one, lowering $# as well.
Taught in
- Option Parsing With getopts — Bash Scripting & Command Line Automation