getopt Command Examples
Parse command-line arguments. More information: https://manned.org/getopt.
- Parse optional
verbose/versionflags with shorthands:
getopt {{[-o|--options]}} vV {{[-l|--longoptions]}} verbose,version -- --version --verbose
- Add a
--fileoption with a required argument with shorthand-f:
getopt {{[-o|--options]}} f: {{[-l|--longoptions]}} file: -- --file=somefile
- Add a
--verboseoption with an optional argument with shorthand-v, and pass a non-option parameterarg:
getopt {{[-o|--options]}} v:: {{[-l|--longoptions]}} verbose:: -- --verbose arg
- Accept a
-rand--verboseflag, a--acceptoption with an optional argument and add a--targetwith a required argument option with shorthands:
getopt {{[-o|--options]}} rv::s::t: {{[-l|--longoptions]}} verbose,source::,target: -- -v --target target