GETFLAGS(8)                                           GETFLAGS(8)

          getflags, usage - command-line parsing for shell scripts

          aux/getflags $*


          Getflags parses the flags in its command-line arguments
          according to the environment variable $flagfmt.  This vari-
          able should be a comma-separated list of flag specifiers.
          Each flag is a single letter, optionally followed by a colon
          and a name. It may be followed by a space-separated list of
          argument names.

          Getflags prints an rc(1) script to be evaluated by the call-
          ing program.  For every flag specified in $flagfmt, the gen-
          erated script sets a corresponding environment variable.  If
          the flag specifier contains :name, the corresponding vari-
          able  is named $name.  Otherwise, it is named $flagx.

          After evaluating the script, the environment variables will
          be set as follows: If a flag is not present in the argument
          list, the environment variable will default to the empty
          list.  If the flag is present and takes no arguments, the
          environment variable will be initialized with the string
          '1'.  If the flag takes arguments, the flag's variable will
          be initialized with a list of those argument values.  The
          script then sets the variable $* to the list of remaining
          non-flag arguments.

          The $status is variable to the empty string on success, or
          'usage' when there is an error parsing the command line.

          Usage prints a usage message to standard error.  The message
          is constructed using $0, $flagfmt, and $args.  The program
          name is taken from $0, as set by rc(1) The list of flags is
          extracted from $flagfmt.  The description of positional
          argument list is taken from $args.

          An example of the script generated:

               % flagfmt='e:example, x, a:arg with args'
               % aux/getflags -exa arg list positional stuff

     Page 1                       Plan 9             (printed 5/15/21)

     GETFLAGS(8)                                           GETFLAGS(8)

               arg=(arg list)
               *=(positional stuff)

          Parse the arguments for leak(1):

               flagfmt='b:showbmp, s:acidfmt, f binary, r res, x width'
               args='name | pid list'
               if(! ifs=() eval `{aux/getflags $*} || ~ $#* 0){
                    exit usage
               if(~ $#showbmp 0)
                    echo '-b flag not set'
               echo $showbmp  # named
               echo $acidfmt  # also named
               echo $flagf    # default name
               echo $flagr    # default name



     Page 2                       Plan 9             (printed 5/15/21)