一:posix约定:

下面是POSIX标准中关于程序名、参数的约定:

程序名不宜少于2个字符且不多于9个字符;

程序名应只包含小写字母和阿拉伯数字;

选项名应该是单字符或单数字,且以短横 ‘-’ 为前綴;

多个不需要选项参数的选项,可以合并。(譬如:foo  -a -b -c  ----> foo  -abc)

选项与其参数之间用空白符隔开;

选项参数不可选。

若选项参数有多值,要将其并为一个字串传进来。譬如:myprog -u "arnold,joe,jane"。这种情况下,需要自己解决这些参数的分离问题。

选项应该在操作数出现之前出现。

特殊参数 ‘--’ 指明所有参数都结束了,其后任何参数都认为是操作数。

选项如何排列没有什么关系,但对互相排斥的选项,如果一个选项的操作结果覆盖其他选项的操作结果时,最后一个选项起作用;如果选项重复,则顺序处理。

允许操作数的顺序影响程序行为,但需要作文档说明。

读写指定文件的程序应该将单个参数 ‘-’ 作为有意义的标准输入或输出来对待。

二:getopt

  1. #include <unistd.h>
  2.  
  3. int getopt(int argc, char *const argv[], const char *optstring);
  4. extern char *optarg;</span></span>
  5. extern int opterr, optind, optopt;
  1.  

argc和argv分别是调用main函数时传递的参数。在argv中,以 ‘-’ 开头的元素就是选项。该参数中除了开头的 ‘-’ 以外的字母就是选项字符。如果重复调用getopt函数,则该函数会持续的返回每个选项中的选项字符。

optstring是包含合法选项字符的字符串。该字符串中,每一个字符都可以是合法的选项字符。

如果字符后面跟了一个冒号’:’ ,则说明这个选项字符需要一个参数,这个参数要么紧跟在选项字符的后面(同一个命令行参数),要么就是下一个命令行参数。通过指针optarg指向这个参数。

如果字符后面跟了两个冒号’::’ ,则说明该选项字符后面跟可选参数,而且这个可选参数必须紧跟在选项字符的后面(同一个命令行参数,比如-oarg)。如果有参数的话,通过指针optarg指向这个参数,否则,optarg置为NULL。

在GNU的扩展中,如果optstring字符串中包含“W;”(’W’加上一个分号),则 -W foo会被当做长参数 --foo来处理。

变量optind是搜索选项的索引。初始值为1,每次调用getopt函数,optind就会置为下次要开始搜索的参数索引。

getopt函数返回每次找到的选项字符,如果没有选项了,则返回-1。并且,optind置为指向第一个非选项参数的索引。默认情况下,getopt函数在扫描的过程中会重新排序argv,这样,最终所有非选项参数都会排在argv参数表的后面。

示例代码如下:

  1. int main(int argc, char * argv[])
  2. {
  3. int aflag=0, bflag=0, cflag=0;
  4. int i = 0;
  5. int ch;
  6. printf("begin: optind:%d,opterr:%d\n", optind, opterr);
  7. for(i = 0; i < argc; i++)
  8. {
  9. printf("argc[%d]: %s\t", i,argv[i]);
  10. }
  11. printf("\n--------------------------\n");
  12. while ((ch = getopt(argc, argv,"ab::c:de::")) != -1)
  13. {
  14. switch (ch)
  15. {
  16. case 'a':
  17. {
  18. printf("HAVE option:-a\n");
  19. break;
  20. }
  21. case 'b':
  22. {
  23. printf("HAVE option:-b\n");
  24. printf("The argument of -bis %s\n", optarg);
  25. break;
  26. }
  27. case 'c':
  28. {
  29. printf("HAVE option:-c\n");
  30. printf("The argument of -cis %s\n", optarg);
  31. break;
  32. }
  33. case 'd':
  34. {
  35. printf("HAVE option:-d\n");
  36. break;
  37. }
  38. case 'e':
  39. {
  40. printf("HAVE option:-e\n");
  41. printf("The argument of -eis %s\n", optarg);
  42. break;
  43. }
  44. case ':':
  45. {
  46. printf("option %c missingarguments\n", (char)optopt);
  47. break;
  48. }
  49. case '?':
  50. {
  51. printf("Unknown option:%c\n",(char)optopt);
  52. break;
  53. }
  54. default:
  55. {
  56. printf("the option is%c--->%d, the argu is %s\n", ch, ch, optarg);
  57. break;
  58. }
  59. }
  60. printf("optind: %d\n\n",optind);
  61. }
  62. printf("----------------------------\n");
  63. printf("end:optind=%d,argv[%d]=%s\n",optind,optind,argv[optind]);
  64. for(i = 0; i < argc; i++)
  65. {
  66. printf("argc[%d]: %s\t", i,argv[i]);
  67. }
  68. printf("\n");
  69. }

上面的程序,optstring为“ab::c:de::”,说明选项a,d不需要参数,选项c必须有参数,选项b,e有可选参数。如果输入:

./1 
-a  f1  -b  f2  -c  f3  -d  f4  -e  f5

则输出:

begin: optind:1,opterr:1

argc[0]: ./1    argc[1]:-a     argc[2]: f1     argc[3]: -b     argc[4]: f2     argc[5]: -c     argc[6]: f3     argc[7]: -d      argc[8]: f4     argc[9]: -e     argc[10]: f5

--------------------------

HAVE option: -a

optind: 2

HAVE option: -b

The argument of -b is (null)

optind: 4

HAVE option: -c

The argument of -c is f3

optind: 7

HAVE option: -d

optind: 8

HAVE option: -e

The argument of -e is (null)

optind: 10

----------------------------

end:optind=7, argv[7]=f1

argc[0]: ./1    argc[1]:-a     argc[2]: -b     argc[3]: -c     argc[4]: f3     argc[5]: -d     argc[6]: -e     argc[7]: f1      argc[8]: f2     argc[9]: f4     argc[10]: f5

如果optstring的第一个字符是’+’(或者设置了环境变量POSIXLY_CORRECT),则在扫描命令行参数的过程中,一旦碰到非选项参数就会停止。

比如上面的程序,如果optstring为” +ab::c:de::”,如果输入:

./1  -a  f1  -b  f2  -c  f3  -d  f4  -e  f5

输出:

begin: optind:1,opterr:1

argc[0]: ./1    argc[1]:-a     argc[2]: f1     argc[3]: -b     argc[4]: f2     argc[5]: -c     argc[6]: f3     argc[7]: -d      argc[8]: f4     argc[9]: -e     argc[10]: f5

--------------------------

HAVE option: -a

optind: 2

----------------------------

end: optind=2, argv[2]=f1

argc[0]: ./1    argc[1]:-a     argc[2]: f1     argc[3]: -b     argc[4]: f2     argc[5]: -c     argc[6]: f3     argc[7]: -d      argc[8]: f4     argc[9]: -e     argc[10]: f5

如果optstring的第一个字符是’-’,则所有的非选项参数都会被当做数字1的选项的参数。         比如上面的程序,如果optstring为” -ab::c:de::”,如果输入:

./1  -a  f1  -b  f2  -c  f3  -d  f4  -e  f5

输出:

begin: optind:1,opterr:1

argc[0]: ./1    argc[1]:-a     argc[2]: f1     argc[3]: -b     argc[4]: f2     argc[5]: -c     argc[6]: f3     argc[7]: -d      argc[8]: f4     argc[9]: -e     argc[10]: f5

--------------------------

HAVE option: -a

optind: 2

the option is --->1, the argu is f1

optind: 3

HAVE option: -b

The argument of -b is (null)

optind: 4

the option is --->1, the argu is f2

optind: 5

HAVE option: -c

The argument of -c is f3

optind: 7

HAVE option: -d

optind: 8

the option is --->1, the argu is f4

optind: 9

HAVE option: -e

The argument of -e is (null)

optind: 10

the option is --->1, the argu is f5

optind: 11

----------------------------

end: optind=11,argv[11]=(null)

argc[0]: ./1   argc[1]: -a     argc[2]: f1     argc[3]: -b     argc[4]: f2     argc[5]: -c     argc[6]: f3     argc[7]: -d      argc[8]: f4     argc[9]: -e     argc[10]: f5

如果在命令行参数中有’--’,不管optstring是什么,扫描都会停止。

比如上面的程序,如果optstring为” ab::c:de::”如果输入:

./getopt  -a  f1  -b  f2  --  -c  f3  -d  f4  -e  f5

输出:

begin: optind:1,opterr:1

argc[0]: ./1    argc[1]:-a     argc[2]: f1     argc[3]: -b     argc[4]: f2     argc[5]: --     argc[6]: -c     argc[7]: f3      argc[8]: -d     argc[9]: f4     argc[10]: -e    argc[11]: f5

--------------------------

HAVE option: -a

optind: 2

HAVE option: -b

The argument of -b is (null)

optind: 4

----------------------------

end: optind=4,argv[4]=f1

argc[0]: ./1    argc[1]:-a     argc[2]: -b     argc[3]: --     argc[4]: f1     argc[5]: f2     argc[6]: -c     argc[7]: f3      argc[8]: -d     argc[9]: f4     argc[10]: -e    argc[11]: f5

如果命令行参数中,有optstring中没有的字符,则将会打印错误信息,并且将这个字符存储到optopt中,返回 ’?’。如果不想打印错误信息,则可以设置变量opterr为0.

比如上面的程序,如果optstring为"ab::c:de::”,

如果输入:./getopt -a  f1  -b  f2  -t  -c  f3

则输出:

begin: optind:1,opterr:1

argc[0]: ./1    argc[1]:-a     argc[2]: f1     argc[3]: -b     argc[4]: f2     argc[5]: -t     argc[6]: -c     argc[7]: f3

--------------------------

HAVE option: -a

optind: 2

HAVE option: -b

The argument of -b is (null)

optind: 4

./1: invalid option -- t

Unknown option: t

optind: 6

HAVE option: -c

The argument of -c is f3

optind: 8

----------------------------

end: optind=6,argv[6]=f1

argc[0]: ./1   argc[1]: -a     argc[2]: -b     argc[3]: -t     argc[4]: -c     argc[5]: f3     argc[6]: f1     argc[7]: f2

如果某个选项字符后应该跟参数,但是命令行参数中没有,则根据optstring中的首字符的不同返回不同的值,如果optstring首字符不是’:’ ,则返回 ’?’ ,打印错误信息,并且设置optopt为该选项字符。如果optstring首字符是’:’ (或者首字符是’+’ 、’-’
,且第二个字符是’:’ ),则返回’:’ ,并且设置optopt为该选项字符,但是不在打印错误信息。

比如上面的程序,如果optstring为“ab::c:de::”,如果输入:

./getopt  -a  f1  -b  f2  -c

则输出:

begin: optind:1,opterr:1

argc[0]: ./1    argc[1]:-a     argc[2]: f1     argc[3]: -b     argc[4]: f2     argc[5]: -c

--------------------------

HAVE option: -a

optind: 2

HAVE option: -b

The argument of -b is (null)

optind: 4

./1: option requires an argument -- c

Unknown option: c

optind: 6

----------------------------

end: optind=4,argv[4]=f1

argc[0]: ./1    argc[1]:-a     argc[2]: -b     argc[3]: -c     argc[4]: f1     argc[5]: f2

如果optstring为“:ab::c:de::”,如果输入:

./getopt  -a  f1  -b  f2  -c

则输出:

begin: optind:1,opterr:1

argc[0]: ./1    argc[1]:-a     argc[2]: f1     argc[3]: -b     argc[4]: f2     argc[5]: -c

--------------------------

HAVE option: -a

optind: 2

HAVE option: -b

The argument of -b is (null)

optind: 4

option c missing arguments

optind: 6

----------------------------

end: optind=4,argv[4]=f1

argc[0]: ./1    argc[1]:-a     argc[2]: -b     argc[3]: -c     argc[4]: f1     argc[5]: f2

三:getopt_long和 getopt_long_only

  1. #include <getopt.h>
  2. int getopt_long(int argc, char * const argv[], const char *optstring, const struct option *longopts, int*longindex);
  3.  
  4. int getopt_long_only(int argc, char * const argv[], const char *optstring, const struct option *longopts, int *longindex);

getopt不能处理长选项,也就是’-- ‘开头的选项,处理长选项需要用getopt_long或者getopt_long_only.

getopt_long具有getopt函数的功能,而且还可以处理’--’开头的长选项,一般来说,长选项都有对应的短选项。optstring的意义仅限于短选项,这与getopt中是一致的。如果仅需要该函数处理长选项,则可以将optstring置为空字符串””(不是NULL)。

长选项也可以带参数,比如:--arg=param或 --arg param。

函数参数longopts指向一个数组,该数组元素为structoption,如下:

struct option {

const char*name;

int         has_arg;

int        *flag;

int         val;

};

其中:

name是长参数的名字。

has_arg指明了该长参数是否需要参数,有三种取值,no_argument (or 0)表明不需要参数,required_argument (or 1)表明需要参数,optional_argument(or 2)表明有可选参数。

flag指明了函数返回值,如果flag为NULL,则函数返回val(一般将val设置为长参数对应的短参数)。如果flag不是NULL,则返回0,而且如果相应的长参数找到了,则flag指向的整数被置为val。

该数组的最后一个元素的结构体,成员都要设置为0。

如果longindex不是NULL, 则长参数找到时,它指向的整数被置为相应的longopts数组索引。

上面的getopt程序,如果换成相应的getopt_long调用的话,函数依然工作正常,而且返回打印与getopt一样。说明getopt_long既可以处理短选项,也能处理长选项。

例子如下:

  1. #include <unistd.h>
  2. #include <stdio.h>
  3. #include <getopt.h>
  4. int main(int argc, char * argv[])
  5. {
  6. int aflag=0, bflag=0,cflag=0;
  7. int i = 0;
  8. int ch;
  9. int optionindex = -1;
  10. struct option long_options[] ={
  11. {"add", required_argument, NULL, 'a' },
  12. {"delete", required_argument, NULL, 'd' },
  13. {"verbose",no_argument, NULL, 'v' },
  14. {"create", required_argument, NULL, 'c'},
  15. {"file", required_argument, NULL, 'f' },
  16. {0, 0, 0, 0 }
  17. };
  18.  
  19. printf("begin: optind:%d,opterr:%d\n",optind,opterr);
  20. for(i = 0; i <argc; i++)
  21. {
  22. printf("argc[%d]:%s\t", i, argv[i]);
  23. }
  24. printf("\n--------------------------\n");
  25. while ((ch =getopt_long(argc, argv, "a:d:vc:f:",long_options, &optionindex)) != -1)
  26. {
  27.  
  28. printf("return value is %c\n", ch);
  29. printf("optionindex is %d\n", optionindex);
  30. if(optarg)
  31. {
  32. printf("%c option arguis %s\n", ch, optarg);
  33. }
  34. if(optionindex != -1)
  35. {
  36. printf("long arg nameis %s\n", long_options[optionindex].name);
  37. }
  38. printf("optind:%d\n\n", optind);
  39. }
  40. printf("----------------------------\n");
  41. printf("end:optind=%d,argv[%d]=%s\n",optind,optind,argv[optind]);
  42. for(i = 0; i <argc; i++)
  43. {
  44. printf("argc[%d]:%s\t", i, argv[i]);
  45. }
  46. printf("\n");
  47. }

如果输入:

./1  --add

输出:

begin: optind:1,opterr:1

argc[0]: ./ getoptlong                                     argc[1]: --add

--------------------------

./1: option '--add' requires an argument

return value is ?

optionindex is -1

optind: 2

----------------------------

end: optind=2,argv[2]=(null)

argc[0]: ./1                  argc[1]:--add

如果输入:

./1  --add=a1 f0  --file  f1  -a  a2  -f  f2

begin: optind:1,opterr:1

argc[0]: ./1                  argc[1]:--add=a1      argc[2]: f0                                      argc[3]: --file              argc[4]:f1      argc[5]: -a         argc[6]: a2                                    
argc[7]: -f                    argc[8]:f2

--------------------------

return value is a

optionindex is 0

a option argu is a1

long arg name is add

optind: 2

return value is f

optionindex is 4

f option argu is f1

long arg name is file

optind: 5

return value is a

optionindex is 4

a option argu is a2

long arg name is file

optind: 7

return value is f

optionindex is 4

f option argu is f2

long arg name is file

optind: 9

----------------------------

end: optind=8,argv[8]=f0

argc[0]: ./1                  argc[1]:--add=a1      argc[2]: --file              argc[3]: f1                                      argc[4]:-a      argc[5]: a2        argc[6]: -f                    argc[7]: f2                  
                   argc[8]: f0

可见,在处理既有短选项,又有长选项的情况下,最好每次都把optionindex置为无效值,比如-1,这样就可以区分长短选项了。

如果输入:./1  --add  a1 --cao  f0  --file  f1 -a  a2  -f  f2

begin: optind:1,opterr:1

argc[0]: ./1                  argc[1]:--add             argc[2]: a1                                     argc[3]: --cao             argc[4]:f0      argc[5]: --file    argc[6]: f1                                     
argc[7]: -a                                      argc[8]: a2                        argc[9]: -f          argc[10]: f2

--------------------------

return value is a

optionindex is 0

a option argu is a1

long arg name is add

optind: 3

./1: unrecognized option '--cao'

return value is ?

optionindex is 0

long arg name is add

optind: 4

return value is f

optionindex is 4

f option argu is f1

long arg name is file

optind: 7

return value is a

optionindex is 4

a option argu is a2

long arg name is file

optind: 9

return value is f

optionindex is 4

f option argu is f2

long arg name is file

optind: 11

----------------------------

end: optind=10,argv[10]=f0

argc[0]: ./1                  argc[1]:--add             argc[2]: a1                                     argc[3]: --cao             argc[4]:--file                              argc[5]:f1                                     
argc[6]: -a                                      argc[7]: a2                        argc[8]: -f          argc[9]: f2                   argc[10]:f0

getopt_long_only函数与getopt_long函数类似,只不过把’-’后的选项依然当做长选项,如果一个以’-’开头的选项没有在option数组中找到匹配的选项,但是在optstring中有匹配的短选项,则当成短选项处理。

四:实例

下面的例子来自于开源软件WebBench,一个网站压力测试工具,代码如下:

  1. /* globals */
  2. int http10=1; /* 0 - http/0.9, 1 - http/1.0, 2 - http/1.1 */
  3. #define METHOD_GET 0
  4. #define METHOD_HEAD 1
  5. #define METHOD_OPTIONS 2
  6. #define METHOD_TRACE 3
  7. #define PROGRAM_VERSION "1.5"
  8.  
  9. int method=METHOD_GET;
  10. int clients=1;
  11. int force=0;
  12. int force_reload=0;
  13. int proxyport=80;
  14. char *proxyhost=NULL;
  15. int benchtime=30;
  16.  
  17. static const struct option long_options[]=
  18. {
  19. {"force",no_argument,&force,1},
  20. {"reload",no_argument,&force_reload,1},
  21. {"time",required_argument,NULL,'t'},
  22. {"help",no_argument,NULL,'?'},
  23. {"http09",no_argument,NULL,'9'},
  24. {"http10",no_argument,NULL,'1'},
  25. {"http11",no_argument,NULL,'2'},
  26. {"get",no_argument,&method,METHOD_GET},
  27. {"head",no_argument,&method,METHOD_HEAD},
  28. {"options",no_argument,&method,METHOD_OPTIONS},
  29. {"trace",no_argument,&method,METHOD_TRACE},
  30. {"version",no_argument,NULL,'V'},
  31. {"proxy",required_argument,NULL,'p'},
  32. {"clients",required_argument,NULL,'c'},
  33. {NULL,0,NULL,0}
  34. };
  35.  
  36. static void usage(void)
  37. {
  38. fprintf(stderr,
  39. "webbench [option]... URL\n"
  40. " -f|--force Don't wait for reply from server.\n"
  41. " -r|--reload Send reload request - Pragma: no-cache.\n"
  42. " -t|--time <sec> Run benchmark for <sec> seconds. Default 30.\n"</span>
  43. " -p|--proxy <server:port> Use proxy server for request.\n"
  44. " -c|--clients <n> Run <n> HTTP clients at once. Default one.\n"
  45. " -9|--http09 Use HTTP/0.9 style requests.\n"
  46. " -1|--http10 Use HTTP/1.0 protocol.\n"
  47. " -2|--http11 Use HTTP/1.1 protocol.\n"
  48. " --get Use GET request method.\n"
  49. " --head Use HEAD request method.\n"
  50. " --options Use OPTIONS request method.\n"
  51. " --trace Use TRACE request method.\n"
  52. " -?|-h|--help This information.\n"
  53. " -V|--version Display program version.\n"
  54. );
  55. };
  56.  
  57. void printval()
  58. {
  59. printf("force is %d\n", force);
  60. printf("force_reload is %d\n", force_reload);
  61. printf("benchtime is %d\n", benchtime);
  62. printf("proxyhost:proxyport is %s:%d\n", proxyhost, proxyport);
  63. printf("clients is %d\n", clients);
  64. printf("http10 is %d\n", http10);
  65. printf("method is %d\n", method);
  66. }
  67.  
  68. int main(int argc, char *argv[])
  69. {
  70. int opt=0;
  71. int options_index=0;
  72. char *tmp=NULL;
  73.  
  74. if(argc==1)
  75. {
  76. usage();
  77. return 2;
  78. }
  79.  
  80. while((opt=getopt_long(argc,argv,"912Vfrt:p:c:?h",long_options, &options_index))!=EOF)
  81. {
  82. printf("opt is %d(%c)\n", opt, opt);
  83. switch(opt)
  84. {
  85. case 0 : break;
  86. case 'f': force=1;break;
  87. case 'r': force_reload=1;break;
  88. case '9': http10=0;break;
  89. case '1': http10=1;break;
  90. case '2': http10=2;break;
  91. case 'V': printf(PROGRAM_VERSION"\n");exit(0);
  92. case 't': benchtime=atoi(optarg);break;
  93. case 'p':
  94. /* proxy server parsing server:port */
  95. tmp=strrchr(optarg,':');
  96. proxyhost=optarg;
  97. if(tmp==NULL)
  98. {
  99. break;
  100. }
  101. if(tmp==optarg)
  102. {
  103. fprintf(stderr,"Error in option --proxy %s: Missing hostname.\n",optarg);
  104. return 2;
  105. }
  106. if(tmp==optarg+strlen(optarg)-1)
  107. {
  108. fprintf(stderr,"Error in option --proxy %s Port number is missing.\n",optarg);
  109. return 2;
  110. }
  111. *tmp='\0';
  112. proxyport=atoi(tmp+1);break;
  113. case ':':
  114. case 'h':
  115. case '?': usage();return 2;break;
  116. case 'c': clients=atoi(optarg);break;
  117. }
  118. }
  119.  
  120. if(optind==argc)
  121. {
  122. fprintf(stderr,"webbench: Missing URL!\n");
  123. usage();
  124. return 2;
  125. }
  126.  
  127. printval();
  128. printf("argv[optind] is %s\n", argv[optind]);
  129. }

getopt、getopt_long和getopt_long_only解析命令行参数的更多相关文章

  1. linux 中解析命令行参数(getopt_long用法)

    linux 中解析命令行参数(getopt_long用法) http://www.educity.cn/linux/518242.html 详细解析命令行的getopt_long()函数 http:/ ...

  2. Windows下解析命令行参数

    linux通常使用GNU C提供的函数getopt.getopt_long.getopt_long_only函数来解析命令行参数. 移植到Windows下 getopt.h #ifndef _GETO ...

  3. C语言中使用库函数解析命令行参数

    在编写需要命令行参数的C程序的时候,往往我们需要先解析命令行参数,然后根据这些参数来启动我们的程序. C的库函数中提供了两个函数可以用来帮助我们解析命令行参数:getopt.getopt_long. ...

  4. python解析命令行参数

    常常需要解析命令行参数,经常忘记,好烦,总结下来吧. 1.Python 中也可以所用 sys 的 sys.argv 来获取命令行参数: sys.argv 是命令行参数列表 参数个数:len(sys.a ...

  5. boost之program_options库,解析命令行参数、读取配置文件

    一.命令行解析 tprogram_options解析命令行参数示例代码: #include <iostream> using namespace std; #include <boo ...

  6. optparse模块解析命令行参数的说明及优化

    一.关于解析命令行参数的方法 关于“解析命令行参数”的方法我们一般都会用到sys.argv跟optparse模块.关于sys.argv,网上有一篇非常优秀的博客已经介绍的很详细了,大家可以去这里参考: ...

  7. getopt_long函数解析命令行参数

    转载:http://blog.csdn.net/hcx25909/article/details/7388750 每一天你都在使用大量的命令行程序,是不是感觉那些命令行参数用起来比较方便,他们都是使用 ...

  8. Shell 参数(2) --解析命令行参数工具:getopts/getopt

    getopt 与 getopts 都是 Bash 中用来获取与分析命令行参数的工具,常用在 Shell 脚本中被用来分析脚本参数. 两者的比较 (1)getopts 是 Shell 内建命令,geto ...

  9. getopt函数的使用——分析命令行参数

    getopt(分析命令行参数) getopt(分析命令行参数) 短参数的定义 返回值 范例 getopt_long 相关函数表头文件#include<unistd.h> 函数声明int g ...

随机推荐

  1. tomcat的三种部署项目的方式

    1.直接将项目放在webapps目录下. 如果将项目直接打成WAR包,放在webapps目录下会自动解压 项目的文件夹名称就是项目的访问路径,也就是虚拟目录. 2.配置conf文件夹下的server. ...

  2. 避免SQL注入三慷慨法

    版权声明:本文为博主原创文章,未经博主同意不得转载. https://blog.csdn.net/wangyy130/article/details/26154837       要说SQL注入还要从 ...

  3. springMVC--动态验证码实现

    在网站开发过程中我们一般都会为了防止用户连续提交都会提供验证码的功能,简单来说就是生成一个动态图片,在图片中保存一些校验信息,将校验信息放到session中和用户提交的验证码信息进行对比,如果出现错误 ...

  4. 【react】react-reading-track

    这是一个很有趣的图书阅读demo 先放github地址:https://github.com/onlyhom/react-reading-track 我觉得这个博主的项目很有意思呢 我们一起看看代码啊 ...

  5. token流程图

  6. js面向对象开发基础

    js的面向对象开发能力较弱,基本是以prototype为核心的面向对象,虽然现在出了个class这玩意,但本文还是先不做探讨. 面向对象基础——构造函数方法 var Fly = function (s ...

  7. 【GDOI2017 day2】凡喵识图 二进制切分

    题面 100 有一个显然的做法是\(O(n^2)\): 想办法优化这个做法: 我们给一个64位整数,切分成四个16位整数. 那么如果两个64位整数符合汉明距离为3的话,那么两者切分的四个16位整数中: ...

  8. JDK的KEYTOOL的应用,以及签署文件的应用(原创)

    首先,我是这样的情况下学到这部分知识的: 我们公司同事把自己的unity生成的APK包查出MD5值直接拿出去微信那边申请,当然这样本来是没毛病,毕竟当时只有他一个人开发这个游戏, 然而我们几个前端过去 ...

  9. 一个不错的插件(软件).NET开发

    http://www.gcpowertools.com.cn/products/default.htm 葡萄城 先记录一下!

  10. 每日算法之三十四:Multiply Strings

    大数相乘,分别都是用字符串表示的两个大数.求相乘之后的结果表示. 首先我们应该考虑一下測试用例会有哪些,先准备測试用例对防御性编程会有比較大的帮助.可以考虑一些极端情况.有以下几种用例: 1)&quo ...