GETFLAGS(8)
GETFLAGS(8) π
okay bestie, welcome to the System Manager's Manual page for getflags and usage β the command-line parsing duo for shell scripts. no cap, this one's a lil niche but it's literally the backbone of your rc script vibes. β¨
β¨ NAME β¨
getflags,usageβ command-line parsing for shell scripts π«Ά
πΈ SYNOPSIS πΈ
getflags $*
usage [ progname ]
π DESCRIPTION π
Getflags is the main character here: it parses the options in its command-line arguments according to the environment variable $flagfmt. π
That $flagfmt variable should be a list of comma-separated options. Each option can be either:
- a single letter β meaning it takes no arguments, or
- a letter followed by the space-separated names of its arguments.
Getflags prints an rc(1) script on standard output which initializes the environment variable $flagx for every option mentioned in $flagfmt. π
Here's the tea on what that script does:
- If the option is not present on the command-line, the script sets that option's flag variable to an empty list. π«§
- Otherwise, the script sets that option's flag variable with a list containing the option's arguments or, if the option takes no arguments, with the string
1. π₯ - The script also sets the variable
$*to the list of arguments following the options. - The final line in the script sets the
$statusvariable β to the empty string on success, and to the stringusagewhen there is an error parsing the command line. π
Usage prints a usage message to standard error. It creates the message using $flagfmt (as described above), $args β which should contain the string to be printed explaining non-option arguments β and $0, the program name (see rc(1)). π
If run under sh(1), which does not set $0, the program name must be given explicitly on the command line. fr fr, don't forget it. π
π EXAMPLE π
Parse the arguments for Plan 9's leak(1):
flagfmt='b,s,f binary,r res,x width'
args='name | pid list'
if(! ifs=() eval `{getflags $*} || ~ $#* 0){
usage
exit usage
}
π¦ SOURCE π¦
/src/cmd/getflags.c/src/cmd/usage.c
π SEE ALSO π
mwah π this has been GETFLAGS(8) from the System Manager's Manual β source lives at /src/cmd/getflags.c and /src/cmd/usage.c. periodt. π
π¦ where this page comes from
- alpine 3.24: plan9port-doc 0_git20260208-r0 Β· LPL-1.02
- arch rolling: plan9port 20261021-2 Β· custom
- nixos 26.05: plan9port 0-unstable-2025-11-10
- nixos 26.05: plan9port-wayland 0-unstable-2025-11-26
- nixpkgs unstable: plan9port 0-unstable-2025-11-10
- nixpkgs unstable: plan9port-wayland 0-unstable-2025-11-26
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms