-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgetopt_test.c
71 lines (69 loc) · 1.39 KB
/
getopt_test.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
#include<stdio.h>
#include<string.h>
#include<unistd.h>
/*
int main(int argc,char **argv)
{
int ch;
opterr = 0;
char command[512] = {0};
strcpy(command, "lvs -o,lv_uuid ");
while((ch = getopt(argc,argv,"l:de::"))!= -1)
{
switch(ch)
{
case 'l':
strcat(command, optarg);
strcat(command, "|grep -v 'LV UUID'>/tmp/.osnlv_uuid");
system(command);
//system("cat /tmp/.osnlv_uuid");
break;
case 'e':
printf("e:%s\n", optarg);break;
case 'n':
printf("n:\n");break;
case 'd':
printf("d:\n");break;
default:
printf("%c: unknow para\n",ch);break;
}
}
int i;
for(i = 0; i < argc; i++)
printf("%s\n", argv[i]);
}
*/
int main(int argc,char *argv[])
{
int ch;
opterr=0;
while((ch=getopt(argc,argv,"a:b:cd"))!=-1)
{
printf("ch: %c\n",ch);
printf("optind: %d\n",optind);
printf("argv[%d]: %s\n",optind, argv[optind]);
printf("optarg: %s\n",optarg);
printf("optopt: %c\n",optopt);
printf("=============\n");
/*
switch(ch)
{
case 'a':
printf("option a: '%s'\n",optarg);
break;
case 'b':
printf("option b: '%s'\n",optarg);
break;
case 'c':
printf("option c\n");
break;
case 'd':
printf("option d\n");
break;
default:
printf("other option: %c\n",ch);
}
*/
}
printf("optind: %d\n",optind);
}