1
0
Fork 0
mirror of https://github.com/tldr-pages/tldr.git synced 2025-04-29 23:24:55 +02:00
tldr/pages/linux/getopt.md

21 lines
858 B
Markdown
Raw Normal View History

2021-10-23 20:36:21 +02:00
# getopt
2023-05-30 20:37:28 +02:00
> Parse command-line arguments.
> More information: <https://manned.org/getopt>.
2021-10-23 20:36:21 +02:00
- Parse optional `verbose`/`version` flags with shorthands:
`getopt {{[-o|--options]}} vV {{[-l|--longoptions]}} verbose,version -- --version --verbose`
2021-10-23 20:36:21 +02:00
- Add a `--file` option with a required argument with shorthand `-f`:
`getopt {{[-o|--options]}} f: {{[-l|--longoptions]}} file: -- --file=somefile`
2021-10-23 20:36:21 +02:00
- Add a `--verbose` option with an optional argument with shorthand `-v`, and pass a non-option parameter `arg`:
`getopt {{[-o|--options]}} v:: {{[-l|--longoptions]}} verbose:: -- --verbose arg`
2021-10-23 20:36:21 +02:00
- Accept a `-r` and `--verbose` flag, a `--accept` option with an optional argument and add a `--target` with a required argument option with shorthands:
`getopt {{[-o|--options]}} rv::s::t: {{[-l|--longoptions]}} verbose,source::,target: -- -v --target target`