I spent quite a while researching the problem I encountered but none of the getopts tutorial say anything about the leading whitespace in OPTARG when using getopts.
In bash(on Ubuntu and OSX), executing below commands:
OPTIND=1 && getopts ":n:" opt "-n 1" && echo "OPTARG: '$OPTARG'"
and it echos:
OPTARG: ' 1'
However, if I execute this:
OPTIND=1 && getopts ":n:" opt "-n1" && echo "OPTARG: '$OPTARG'"
then I will get what I expect:
From what I read online:
Normally one or more blanks separate the value from the option letter; however, getopts also handles values that follow the letter immediately [Reference]
If the above quote is universally right for getopts, what do I do wrong that I get that leading whitespace in OPTARG?