OPTARG
The variable getopts fills with the value of an option that takes one, such as the file name after -f.
In more detail
Read it inside the case branch for that option, because the next call to getopts overwrites it. In silent error mode it holds the offending option letter instead.
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.
- OPTIND — The variable getopts uses to track which argument it will read next; after the loop it points at the first operand.
- option string — The string given to getopts listing the option letters a script accepts, with a colon after each letter that takes a value.
Taught in
- Arguments: Dollar One, Dollar At, shift — Bash Scripting & Command Line Automation
- Option Parsing With getopts — Bash Scripting & Command Line Automation