O'Reilly logo

Advanced Mac OS X Programming: The Big Nerd Ranch Guide by Mark Dalrymple

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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. ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required