getopt实用的 char *string=optarg; error: syntax error before "char" 不能这样吗? [ 本帖最后由 darkslack 于 2007-9-20 14:07 编辑 ]
[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没有定义,是要自己来写吗?但是...
#!/bin/bash ALL=false HELP=false FILE=false COPIES=0 while getopts :ahfgc: OPTION do case $OPTION in a)ALL=true echo "ALL is $ALL" ;; h)HELP=true echo "HELP IS $HELP" ;; f)FILE=true echo "FILE IS $FILE" ;; c)COPIES=$optarg echo "COPIES IS $COPIES" \?)echo "`basename $0` -[c value]" >&2 ;; esac done 以上是脚本的内容,文件名为fun.sh 在命令行输入./fun.sh -ah -c 显示 ./fun....
感觉gdb不大好用 程序可以正常运行,但这两个变量确一直是初始值,比如optind=1,optarg=0; 必须要事先把他们声明为全局变量才可以吗? 是不是还有会有多类似问题出现 或者是我gdb用的还不熟悉,导致了此类情况出现 请高手赐教
请问getopts和optarg是什么关系,下面这段关系中,莫名其妙的出现了optart这个参数,我不知道什么意思,请这里的各位给我讲讲,谢谢!!! #!/bin/bash #getopts ALL=false FILE=false HISTORY=false VERBOSE=false HELP=false while getopts afhvhc OPTION do case $OPTION in a) ALL=true echo "ALL IS $ALL." ;; f) FILE=true echo "FILE IS ...
[test]$ more test.sh while getopts ab c;do case $c in a) echo $optarg;; b) echo $optarg;; \?) echo "Unknow char $c";; esac done 运行下面的命令:[test]test.sh -a 983 没有任何输出???