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 O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.