俺是SHELL菜鸟,这几天看了新手导航版块里waker 介绍的帖子。 其中设计到$optind的问题一直没弄明白,不知道具体$optind的值是如何递增的。 在cuci大大的文章http://bbs.chinaunix.net/viewthread.php?tid=557642中有如下代码 #--拷贝程序 COPIES=1 VERBOSE=N while getopts vc:OPTION do case $OPTION in c)COPIES=$optarg;; v)VERBOSE=Y;; \?)e...
getopt实用的 char *string=optarg; error: syntax error before "char" 不能这样吗? [ 本帖最后由 darkslack 于 2007-9-20 14:07 编辑 ]
[code][root@GO-EMAIL-1 ~]# cat 1.sh #!/bin/bash echo $* while getopts "ab:cd:" Option # b and d take arguments # do case $Option in a) echo -e "a = $optind";; b) echo -e "b = $optind $optarg";; c) echo -e "c = $optind";; d) echo -e "d = $optind $optarg";; esac done shift $(($optind - 1)) [root@GO-EMAIL-1 ~]# sh 1.sh -ab foo -ab foo a = 1 b = 3 foo [/code]1.-ab是如何理解的,是一个option还是2个optio...
[code]while((opt = getopt(argc, argv, "o:a:s:")) != EOF) { switch(opt) { case 'o': offset = atoi(optarg); break; case 'a': align = atoi(optarg); break; case 's': server = (char *)malloc(strlen(optarg) + 1); server = optarg; break; default: usage(argv[0]); break; }[/code] 编译时总是提示optarg没有定义,是要自己来写吗?但是...
[code] while getopts ":abcde:fg" Option # Initial declaration. # 开始的声明. # a, b, c, d, e, f, 和 g 被认为是选项(标志). # e 选项后边的:提示,这个选项带一个参数. do case $Option in a ) # Do something with variable 'a'. echo aaa ;; b ) # echo bbb ;; e) # Do something with 'e', and also with $optarg, echo eee with $optarg ;; g ) # 对选项'g'作些操作. echo ggg ;; esac done shift $(($optind - 1)) # 将参...
The variable optind is the index of the next element to be processed in argv. The system initializes this value to 1. The caller can reset it to 1 to restart scanning of the same argv, or when scanning a new argument vector. If getopt() finds another option character, it returns that character, updating the external variable optind and a static variable next...
有这样一个关于optind的脚本,运行后发现optind分别是1,3,5,请教大家,这是为什么呢? 脚本: #!/bin/sh # test_getopts while getopts "xy:z:" name do echo "$name" $optind $optarg done 执行: test_getopts -xy 110 -z 220 结果: x 1 y 3 110 z 5 220