getopt
Outputs command line with recognized OPTIONS character arguments moved to front, then "--", then non-option arguments. toybox
On Linux
Linux
Outputs command line with recognized OPTIONS character arguments moved to front, then "--", then non-option arguments. Returns 1 if unknown options. OPTIONS followed by : take an argument, or :: for optional arguments (which must be attached, ala -xblah or --long=blah).
getopt [-aTu] [-lo OPTIONS] [-n NAME] [OPTIONS] ARG...
-aAllow long options starting with a single --l OPTIONSLong OPTIONS (repeated or comma separated)-n NAMECommand NAME for error messages-o OPTIONSShort OPTIONS (instead of using first argument)-TTest whether this is a modern getopt-uUnquoted output (default if no other options set) $ getopt -l long:,arg:: abc command --long -b there --arg--long'-b' --arg '' -- 'command' 'there'Linux
Parse command-line arguments.
Parse optional verbose/version flags with shorthands
getopt --options vV --longoptions verbose,version -- --version --verboseIdentifyAdd a --file option with a required argument with shorthand -f
getopt --options f: --longoptions file: -- --file=somefileIdentifyAdd a --verbose option with an optional argument with shorthand -v, and pass a non-option parameter arg
getopt --options v:: --longoptions verbose:: -- --verbose argIdentifyAccept a -r and --verbose flag, a --accept option with an optional argument, and add a --target with a required argument option with shorthands
getopt --options rv::s::t: --longoptions verbose,source::,target: -- -v --target targetIdentify