3 getflags, usage \- command-line parsing for shell scripts
10 parses the flags in its command-line arguments
11 according to the environment variable
13 This variable should be a comma-separated list of flag specifiers.
14 Each flag is a single letter, optionally followed by a
15 colon and a name. It may be followed by a space-separated
16 list of argument names.
22 script to be evaluated by the calling program.
23 For every flag specified in
25 the generated script sets a corresponding environment variable.
26 If the flag specifier contains
28 the corresponding variable is named
30 Otherwise, it is named
34 After evaluating the script, the environment variables will
36 If a flag is not present in the argument list, the environment
37 variable will default to the empty list.
38 If the flag is present and takes no arguments, the environment
39 variable will be initialized with the string
41 If the flag takes arguments, the flag's variable will be initialized
42 with a list of those argument values.
43 The script then sets the variable
45 to the list of remaining non-flag arguments.
49 is variable to the empty string on success, or
51 when there is an error parsing the command line.
54 prints a usage message to standard error.
55 The message is constructed using
60 The program name is taken from
64 The list of flags is extracted from
66 The description of positional argument list is taken from
71 An example of the script generated:
74 % flagfmt='e:example, x, a:arg with args'
75 % aux/getflags -exa arg list positional stuff
86 Parse the arguments for
90 flagfmt='b:showbmp, s:acidfmt, f binary, r res, x width'
91 args='name | pid list'
92 if(! ifs=() eval `{aux/getflags $*} || ~ $#* 0){
97 echo '-b flag not set'
99 echo $acidfmt # also named
100 echo $flagf # default name
101 echo $flagr # default name
104 .B /sys/src/cmd/aux/getflags.c
106 .B /sys/src/cmd/aux/usage.c