Jump to content

getopts

From Wikipedia, the free encyclopedia

This is an old revision of this page, as edited by Teceha (talk | contribs) at 07:59, 20 February 2012 (→‎History: Bash link). The present address (URL) is a permanent link to this revision, which may differ significantly from the current revision.

getopts is a built-in Unix shell command for parsing command-line arguments.

It is designed to process command line arguments that follow the POSIX Utility Syntax Guidelines.

History

Getopts was first introduced in 1986 in the Bourne shell shipped with Unix SVR3[1]. Earlier versions of the Bourne shell did not have getopts. Note: getopts is not the same as getopt.

Currently, getopts is available in a number of shells, including: Bourne shell, Korn shell and Bash.

getopt (original)

The getopts was developed as an improvement to the original getopt Unix program.

The original getopt program has less 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 a 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. Both being improvements to the original getopt Unix program.

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 option1 option2 option3 -a -b is permitted by the GNU enhanced version of getopt but does not work as expected with getopts).

The GNU enhanced version of getopt is an external command line program (unlike getopts which is a built-in shell command).

See also

References

  1. ^ Mascheck, Sven. "The Traditional Bourne Shell Family". Retrieved 2010-12-01.