This article was accepted into the corpus but its outbound wikilinks were never NER-processed — typical at the deepest BFS hop or when the run's entity cap was reached. No expansion funnel to show.
| GNU Getopt | |
|---|---|
| Name | GNU Getopt |
| Developer | GNU Project |
| Released | 1989 |
| License | GNU General Public License |
| Platform | Unix-like |
GNU Getopt GNU Getopt is a program and library component for parsing command-line options on Unix-like systems. It is distributed by the GNU Project and commonly used in software distributed by the Free Software Foundation, included in many Linux distributions such as Debian and Red Hat Enterprise Linux. Maintained alongside utilities like GNU Coreutils and integration with build tools such as autoconf and automake, it has influenced option parsing in projects from GCC to GNU Emacs.
GNU Getopt evolved from earlier option parsing conventions established in the Unix tradition, influenced by implementations in AT&T Bell Labs research and tools shipped with BSD releases. With the rise of the Free Software Foundation in the 1980s, the GNU Project formalized a portable Getopt to support portability across System V and BSD variants. Over time, contributions from maintainers associated with projects like GCC and GNU Coreutils extended functionality to accommodate long options and enhanced error reporting, paralleling developments in other utilities such as getopt_long implementations found in glibc.
Getopt provides standardized parsing of single-character options and optional arguments, with features that include support for long-form options, automated generation of usage messages, and return values signifying option parsing state. It interoperates with environments like the POSIX shell and libraries used by Perl, Python, and Ruby bindings where compatibility with existing tools including tar and sed is important. Implementations often provide reentrant interfaces suitable for integration with projects such as systemd or OpenSSL.
GNU Getopt is invoked either as a command-line utility or via the C library function exposed in headers provided by glibc and other C standard libraries. Developers in projects like bind and curl use the API to map argv vectors to option tokens, enabling consistent behavior across platforms like FreeBSD and NetBSD. Scripting projects in Debian packaging and automation frameworks such as Ansible rely on predictable option parsing produced by Getopt-compatible tools.
The option descriptors accepted by Getopt follow conventions that mirror POSIX specifications and extensions found in the GNU Coding Standards. Short options (single dash) and long options (double dash) are supported, including optional arguments indicated in descriptor strings. Error handling and permutation of non-option arguments follow rules also referenced in documentation for POSIX.1-2001 and implementations used by projects such as Coreutils and GnuPG.
The canonical implementation is written in C and distributed with glibc and the GNU C Library ecosystem; alternate implementations appear in portability layers for musl and other C runtimes. Language bindings and wrappers exist for high-level projects including Perl (Getopt::Long), Python (argparse historically influenced by getopt semantics), and Ruby (OptionParser), enabling integration with larger systems such as Apache HTTP Server modules and OpenSSH utilities. The API exposes functions that process argc/argv arrays and return standardized option codes used by programs like ls, grep, and make.
Compatibility concerns have led to multiple implementations and alternatives: the original Unix getopt, GNU extensions like getopt_long, and third-party libraries such as argp and modern option parsers in Boost and Qt for C++ projects. Cross-platform projects such as CMake or LLVM sometimes prefer bespoke parsers or libraries (e.g., LLVM Command Line Library) to avoid subtle differences between glibc and other libc implementations. In scripting ecosystems, alternatives such as getopts in shell builtins or high-level parsers like docopt and optparse appear depending on project needs.
Common patterns include parsing typical option sets (e.g., -h/--help, -v/--version) in utilities maintained by the GNU Project and packaging scripts for distributions such as Ubuntu and Fedora. Integration examples appear in build systems like autotools and deployment scripts for Kubernetes where consistent option handling is required. Real-world uses include command-line front ends for GnuPG, wrapper scripts in Debian packages, and utilities bundled with BusyBox that emulate Getopt-compatible behavior.