variable

OPTARG

Value of an option requiring an argument. In silent error mode contains the offending option character. It may be unset for flags without a value; do not assume it always exists.

Formal Syntax & Structure

bash syntaxbash
$OPTARG

Return Value

string or unset

Value of an option requiring an argument. In silent error mode contains the offending option character. It may be unset for flags without a value; do not assume it always exists.

Working Example

Example Snippetbash
set -- -nOPTIND=1getopts ':n:' optstatus=$?printf 'opt=%s arg=%s status=%s\n' "$opt" "$OPTARG" "$status"
Bash Reference