GETFLAGS(8)
πΈ NAME πΈ
okay bestie, you're on the GETFLAGS(8) page from the System Manager's Manual, and it's giving "command-line parsing for shell scripts" π
. The stars are getflags and usage, and yes they share a page because they're a package deal. π«Ά
getflags, usage β command-line parsing for shell scripts.
π«Ά SYNOPSIS π«Ά
getflags $*
usage [ progname ]
π DESCRIPTION π
getflags parses the options in its command-line arguments according to the environment variable $flagfmt. That variable should be a list of comma-separated options. Each option can be:
- a single letter, which means it does not take arguments, or
- a letter followed by the space-separated names of its arguments.
Then getflags prints an rc(1) script on standard output. That script initializes the environment variable $flagx for every option mentioned in $flagfmt. 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 $status variable: to the empty string on success, and to the string usage when 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.
tiny but important, bestie: thatsh(1)situation is real β no$0means you gotta hand over the program name yourself. π
πΈ EXAMPLE πΈ
Parse the arguments for 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 π β that's the GETFLAGS(8) page from the System Manager's Manual. The footer is literally just GETFLAGS(8) with no date attached, so that's the whole sign-off: bye bestie, go parse those flags slayfully π«Άβ¨
π¦ where this page comes from
- arch rolling: 9base 6-9 Β· custom
- nixpkgs unstable: 9base 6-unstable-2019-09-13
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms