命令行是用户与程序打交道的一个重要途径,为了让用户使用方便,程序员需要设计出相应的函数对命令行进行解析. 在linux等系统中, getopt函数就是干这个的,下面摘录Wikipedia中的资料:(看英语的感觉就是爽啊!)
A long standing issue with command line programs was how to specify options; early programs used many ways of doing so, including single character options (-a
), multiple options specified together (-abc
is equivalent to -a -b -c
), multicharacter options (-inum
), options with arguments (-a arg
, -inum 3
, -a=arg
), and different prefix characters (-a
, +b
, /c
).
The getopt function was written to be a standard mechanism that all