getopt optarg

来源:互联网 发布:usb转网络接口装驱动 编辑:程序博客网 时间:2024/05/18 01:45
[krocp@sdnmanager codes]$ vim getopt.c#include <stdio.h>#include <unistd.h>int main(int argc, char **argv){    int ch;    opterr = 0;    while ((ch = getopt(argc,argv,"a:bcde"))!=-1)    {        switch(ch)        {            case 'a':                printf("option a:'%s'\n",optarg);                break;            case 'b':                printf("option b :b\n");                break;            default:                printf("other option :%c\n",ch);        }    }    printf("optopt +%c\n",optopt);}

运行结果:

[krocp@sdnmanager codes]$ ./getopt -c -a sdafasfdother option :coption a:'sdafasfd'