concept
getopts silent error mode
Leading colon requests caller-managed diagnostics. Unknown option gives ?; missing required argument gives colon. OPTARG names the offending option.
Formal Syntax & Structure
bash syntaxbash
getopts ":vn:" optReturn Value
option marker and status
Leading colon requests caller-managed diagnostics. Unknown option gives ?; missing required argument gives colon. OPTARG names the offending option.
Working Example
Example Snippetbash
set -- -xOPTIND=1getopts ':v' optprintf 'opt=%s arg=%s\n' "$opt" "$OPTARG"