Chapter 26. Parsing Command-Line Options

Most Linux programs allow the user to specify command-line options. Such options perform a wide variety of functions but are fairly uniform in their syntax. Short options consist of a - character followed by a single alphanumeric character. Long options, common in GNU utilities, consist of two - characters followed by a string made up of letters, numbers, and hyphens. Either type of option may be followed by an argument. A space separates a short option from its arguments; either a space or an = separates a long option from an argument.

There are many ways of parsing command-line options. The most popular method is parsing the argv array by hand. The library functions getopt() and getopt_long() provide some ...

Get Linux Application Development, Second Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.