getopt_long()

Parsing Unix command lines correctly is actually a very tricky proposition. You can have individual arguments:

$​ ​s​o​m​e​p​r​o​g​r​a​m​ ​-​a​ ​-​b​ ​-​c​

By convention, you can glom all of the single-character arguments together:

$​ ​s​o​m​e​p​r​o​g​r​a​m​ ​-​a​b​c​

Some arguments can take additional values:

$​ ​s​o​m​e​p​r​o​g​r​a​m​ ​-​d​T​w​i​t​t​e​r​ ​-​f​ ​f​i​l​e​n​a​m​e​

and there are also more verbose (called long) arguments, introduced by two dashes:

$​ ​s​o​m​e​p​r​o​g​r​a​m​ ​-​-​k​t​h​x​ ​-​-​c​h​e​e​z​b​u​r​g​e​r​

There is a convention where -- will terminate processing of command-line arguments and use the remaining contents of the command line as-is, even if they look suspiciously like more command-line arguments. ...

Get Advanced Mac OS X Programming: The Big Nerd Ranch Guide 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.