1 ae03a48b 2009-08-15 rsc .TH GETFLAGS 8
3 ae03a48b 2009-08-15 rsc getflags, usage \- command-line parsing for shell scripts
5 ae03a48b 2009-08-15 rsc .B getflags $*
7 ae03a48b 2009-08-15 rsc .B usage [ progname ]
8 ae03a48b 2009-08-15 rsc .SH DESCRIPTION
10 ae03a48b 2009-08-15 rsc parses the options in its command-line arguments
11 ae03a48b 2009-08-15 rsc according to the environment variable
12 ae03a48b 2009-08-15 rsc .BR $flagfmt .
13 ae03a48b 2009-08-15 rsc This variable should be a list of comma-separated options.
14 ae03a48b 2009-08-15 rsc Each option can be a single letter, indicating that it does
15 ae03a48b 2009-08-15 rsc not take arguments, or a letter followed by the space-separated
16 ae03a48b 2009-08-15 rsc names of its arguments.
20 ae03a48b 2009-08-15 rsc script on standard output which initializes the
21 ae03a48b 2009-08-15 rsc environment variable
23 ae03a48b 2009-08-15 rsc for every option mentioned in
24 ae03a48b 2009-08-15 rsc .BR $flagfmt .
25 ae03a48b 2009-08-15 rsc If the option is not present on the command-line, the script
26 ae03a48b 2009-08-15 rsc sets that option's flag variable to an empty list.
27 ae03a48b 2009-08-15 rsc Otherwise, the script sets that option's flag variable with
28 ae03a48b 2009-08-15 rsc a list containing the option's arguments or,
29 ae03a48b 2009-08-15 rsc if the option takes no arguments,
30 ae03a48b 2009-08-15 rsc with the string
32 ae03a48b 2009-08-15 rsc The script also sets the variable
34 ae03a48b 2009-08-15 rsc to the list of arguments following the options.
35 ae03a48b 2009-08-15 rsc The final line in the script sets the
37 ae03a48b 2009-08-15 rsc variable, to the empty string on success
38 ae03a48b 2009-08-15 rsc and to the string
40 ae03a48b 2009-08-15 rsc when there is an error parsing the command line.
43 ae03a48b 2009-08-15 rsc prints a usage message to standard error.
44 ae03a48b 2009-08-15 rsc It creates the message using
45 ae03a48b 2009-08-15 rsc .BR $flagfmt ,
46 ae03a48b 2009-08-15 rsc as described above,
48 ae03a48b 2009-08-15 rsc which should contain the string to be printed explaining
49 ae03a48b 2009-08-15 rsc non-option arguments,
52 ae03a48b 2009-08-15 rsc the program name
54 d32deab1 2020-08-16 rsc .MR rc (1) ).
57 ae03a48b 2009-08-15 rsc which does not set
59 ae03a48b 2009-08-15 rsc the program name must be given explicitly on the command line.
61 b546bd6e 2017-07-16 rsc Parse the arguments for Plan 9's
62 d32deab1 2020-08-16 rsc .MR leak (1) :
65 ae03a48b 2009-08-15 rsc flagfmt='b,s,f binary,r res,x width'
66 ae03a48b 2009-08-15 rsc args='name | pid list'
67 ae03a48b 2009-08-15 rsc if(! ifs=() eval `{getflags $*} || ~ $#* 0){
73 ae03a48b 2009-08-15 rsc .B \*9/src/cmd/getflags.c
75 ae03a48b 2009-08-15 rsc .B \*9/src/cmd/usage.c