JustBash.Commands.Getopts (JustBash v0.4.0)

View Source

The getopts builtin command - parse positional parameters as options.

Usage: getopts optstring name [args...]

Parses command-line options. Each call processes the next option. Returns 0 if an option is found, 1 when options are exhausted.

The optstring contains the option letters. A colon after a letter means that option requires an argument.

Sets:

  • name: the option letter found (or ? for unknown/missing arg)
  • OPTARG: the option's argument (if any)
  • OPTIND: index of next argument to process