From e9045f60a5e3a6cc859651aaae61cd23f4b53a8f Mon Sep 17 00:00:00 2001 From: Janek <27jf@pm.me> Date: Sat, 23 Oct 2021 20:36:21 +0200 Subject: [PATCH] getopt: add page (#6990) --- pages/linux/getopt.md | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) create mode 100644 pages/linux/getopt.md diff --git a/pages/linux/getopt.md b/pages/linux/getopt.md new file mode 100644 index 0000000000..02deca5a5a --- /dev/null +++ b/pages/linux/getopt.md @@ -0,0 +1,20 @@ +# getopt + +> Parse command line arguments. +> More information: . + +- Parse optional `verbose`/`version` flags with shorthands: + +`getopt -o vV --longoptions verbose,version -- --version --verbose` + +- Add a `--file` option with a required argument with shorthand `-f`: + +`getopt -o f: --longoptions file: -- --file=somefile` + +- Add a `--verbose` option with an optional argument with shorthand `-v`, and pass a non-option parameter `arg`: + +`getopt -o v:: --longoptions verbose:: -- --verbose arg` + +- 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 rv::s::t: --longoptions verbose,source::,target: -- -v --target target`