Advertisement
Guest User

getopts documentation

a guest
Aug 22nd, 2016
208
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.92 KB | None | 0 0
  1. SYNOPSIS
  2. getopts [ options ] opstring name [args...]
  3.  
  4. OPTIONS
  5. -a, --command=name
  6. Use name instead of the command name in usage messages.
  7.  
  8. DESCRIPTION
  9. The getopts utility can be used to retrieve options and arguments from a list
  10. of arguments give by args or the positional parameters if args is omitted. It
  11. can also generate usage messages and a man page for the command based on the
  12. information in optstring.
  13.  
  14. The optstring string consists of alpha-numeric characters, the special
  15. characters +, -, ?, :, and <space>, or character groups enclosed in [...].
  16. Character groups may be nested in {...}. Outside of a [...] group, a single
  17. new-line followed by zero or more blanks is ignored. One or more blank lines
  18. separates the options from the command argument synopsis.
  19.  
  20. Each [...] group consists of an optional label, optional attributes separated
  21. by :, and an optional description string following ?. The characters from the
  22. ? to the end of the next ] are ignored for option parsing and short usage
  23. messages. They are used for generating verbose help or man pages. The :
  24. character may not appear in the label. The ? character must be specified as
  25. ?? in label and the ] character must be specified as ]] in the description
  26. string. Text between two \\b (backspace) characters indicates that the text
  27. should be emboldened when displayed. Text between two \\a (bell) characters
  28. indicates that the text should be emphasised or italicised when displayed.
  29.  
  30. There are four types of groups:
  31. 1. An option specifiation of the form option:longname. In this case the
  32. first field is the option character. If there is no option character,
  33. then a two digit number should be specified that corresponds to the
  34. long options. This negative of this number will be returned as the
  35. value of name by getopts if the long option is matched. A longname is
  36. matched with --longname. A * in the longname field indicates that
  37. only characters up that point need to match provided any additional
  38. characters match the option. The [ and ] can be omitted for options
  39. that don\'t have longnames or descriptive text.
  40. 2. A string option argument specification. Options that take arguments
  41. can be followed by : or # and an option group specification. An
  42. option group specification consists of a name for the option argument
  43. as field 1. The remaining fields are a typename and zero or more of
  44. the special attribute words listof, oneof, and ignorecase. The option
  45. specification can be followed by a list of option value descriptions
  46. enclosed in parenthesis.
  47. 3. A option value description.
  48. 4. A argument specification. A list of valid option argument values can
  49. be specified by enclosing them inside a {...} following the option
  50. argument specification. Each of the permitted values can be specified
  51. with a [...] containing the value followed by a description.
  52.  
  53. If the leading character of optstring is +, then arguments beginning with +
  54. will also be considered options.
  55.  
  56. A leading : character or a : following a leading + in optstring affects the
  57. way errors are handled. If an option character or longname argument not
  58. specified in optstring is encountered when processing options, the shell
  59. variable whose name is name will be set to the ? character. The shell
  60. variable OPTARG will be set to the character found. If an option argument is
  61. missing or has an invalid value, then name will be set to the : character and
  62. the shell variable OPTARG will be set to the option character found. Without
  63. the leading :, name will be set to the ? character, OPTARG will be unset, and
  64. an error message will be written to standard error when errors are
  65. encountered.
  66.  
  67. The end of options occurs when:
  68. 1. The special argument --.
  69. 2. An argument that does not beging with a -.
  70. 3. A help argument is specified.
  71. 4. An error is encountered.
  72.  
  73. If OPTARG is set to the value 1, a new set of arguments can be used.
  74.  
  75. getopts can also be used to generate help messages containing command usage
  76. and detailed descriptions. Specify args as:
  77. -? To generate a usage synopsis.
  78. --?? To generate a verbose usage message.
  79. --??man
  80. To generate a formatted man page.
  81. --??api
  82. To generate an easy to parse usage message.
  83. --??html
  84. To generate a man page in html format.
  85.  
  86. When the end of options is encountered, getopts exits with a non-zero return
  87. value and the variable OPTIND is set to the index of the first non-option
  88. argument.
  89.  
  90. EXIT STATUS
  91. 0 An option specified was found.
  92. 1 An end of options was encountered.
  93. 2 A usage or information message was generated.
  94.  
  95. IMPLEMENTATION
  96. version getopts (AT&T Research) 1999-02-02'
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement