Getopts was first introduced in 1986 in the Bourne shell shipped with Unix SVR3. Earlier versions of the Bourne shell did not have getopts. (Note: getopts is not the same as the C library function getopt.)
getopts (Solaris enhanced)
In spring 2004 (Solaris 10 beta development), the libc implementation for getopt() was enhanced to support long options. As a result, this new feature was also available in the built-in command getopts of the Bourne Shell.
getopts was developed as an improvement to the original getopt Unix program.
The original getopt program had fewer features than getopts. For example: it did not support whitespaces in arguments, and there was no ability to disable the output of error messages.
The original getopt program was an external command line program (unlike getopts which is a built-in shell command).
getopt (GNU enhanced)
An alternative to getopts is the GNU enhanced version of getopt.
The GNU enhanced version of getopt supports the extra features of getopts plus more advanced features. Most significantly, the GNU enhanced version of getopt supports long option names (e.g.
--help) and the options do not have to appear before all the operands (e.g.
command operand1 operand2 -a operand3 -b is permitted by the GNU enhanced version of getopt but does not work with getopts).
The GNU enhanced version of getopt is an external command line program (unlike getopts which is a built-in shell command).
Summary of features
|getopts||getopts (Solaris enhanced)||getopt (original)||getopt (GNU enhanced)|
|Splitting options for easy parsing||Yes||Yes||Yes||Yes|
|Error messages can be suppressed||Yes||Yes||-||Yes|
|Whitespace allowed in arguments||Yes||Yes||-||Yes|
|Allows operands to be mixed with options||-||Yes||-||Yes|
|Long options support||-||Yes||-||Yes|
- Mascheck, Sven. "The Traditional Bourne Shell Family". Retrieved 2010-12-01.
- The Single UNIX® Specification, Issue 7 from The Open Group : process command line arguments – Commands & Utilities Reference,
|This Unix-related article is a stub. You can help Wikipedia by expanding it.|