Hamilton LaboratoriesHamilton C shell 2012User guideExternal utilities


Oregon Coast

Previous | Next

        Parse Command-Line Options

Usage:  getopt [ -hqC- ] [ -c cmdname ] optionslist arguments ...

   getopt is used in shell scripts for parsing command line
   options into a canonical form, where each option is presented
   in a separate word and any option that takes an argument has
   the argument given in the Next word.

   The list of option characters that should be recognized is
   given as the optionslist argument, e.g., abcz if -a, -b, -c
   and -z options are recogized.  If any option has a colon
   following, e.g., ab:cz, then it requires an argument.

   Scanning for options stops at the first argument which does
   not begin with '-' or '/' or which consists only of '--' or
   '//'.  The SWITCHCHARS environment variable may be used to
   specify a different set of characters other than '-' or '/'
   as the option switch characters to be recognized on input.
   On output, the switch character will be the one that was
   used with that option.


   -h           Help.  ( This screen. )
   -q           Enclose any output words containing C shell word
                separator characters inside double quotes so that
                the word will not be split up when assigning it
                to a variable in a script.  The word Separators
                are:  space, ( , ), ;, |, &, <, >, \n, \r and \t.

                Note:  This option is normally used with eval, e.g.,

                  eval set args = `getopt -q ...`

   -c cmdname   Any Error messages that are produced should say
                they were generated by cmdname, not getopt.
   -C           Canonicalize the output to use '-' as the switchchar
                no matter what switchchar was actually used.
   --           End of options.

Previous | Next