The getopts command is a POSIX Shell built-in command that retrieves options and option-arguments from a list of parameters. An option begins with a - (minus sign) followed by a character. An option that does not begin with a - ends parsing. Each time the getopts command is invoked, it places the value of the next option in Name and the index of the next argument to be processed in the shell variable OPTIND. Whenever the shell is invoked, OPTIND is initialized to 1.
The disadvantage of
getopts is that it
- only parses short option
- can't parse options after non-option arguments
getopt is a command line utility that parses short and long options and rearranges options and non-option arguments.
-a -b, shortOptString is
-a option requires an argument, use
: as in
-a a_arg and
-aa_arg in the same way.
--foo --bar, longOptString is
--foo option requires an argument, use
: as in
--foo arg in the same way.