getopt

Name

getopt -- parse command line options

Synopsis

int getopt(int argc, char * const argv[], const char *opstring);

extern char *optarg;
extern int optind, opterr, optopt;

GNU supports the following extensions of getopt:

int getopt_long(int argc, char * const argv[], const char *opstring, (const struct option *longopts), int *longindex);

int getopt_long_only(int argc, char * const argv[], const char *opstring, (const struct option *longopts), int *longindex);

Description

getopt parses command line arguments. GNU and POSIX specifications for this function vary in the following areas.

Option Characteristics

GNU specifies that:

POSIX specifies that:

Extensions

GNU specifies that:

POSIX specifies that:

Return Values

GNU specifies the following getopt return values:

GNU specifies the following getopt_long and getopt_long_only return values:

POSIX specifies the following getopt return values:

Environmental Variables

GNU specifies that:

Environmental Variables

POSIX.2 Interpretation 150 reports a technical error in the function of getopt. GNU implements the correct behavior of getopt.