ChinaUnix.net
相关文章推荐:

shell getopt

最近写脚本的时候遇到要使用getopt来检查命令行参数是否合法,下面是我的脚本[code] #!/bin/bash ARGS=`getopt -o ab:c:: -l a-long,b-long:,c-long:: -- "$@"` [ $? -ne 0 ] && usage [/code]可是在调用的时候我使用./test.sh --alon的时候它并没有提示错误,我用./test.sh --a-long-t的时候就会提示错误! 是不是getopt在解析的时候匹配不会精确匹配,有没有什么办法让它在./test.sh --alon的时候提示不认识这个选项?

by victorplus - Shell - 2012-07-29 14:26:17 阅读(3474) 回复(9)

相关讨论

LINUX与UNIX shell编程指南上的例子,在linux-bash下运行 代码如下 #!/bin/sh # getopt # modified getopt1 script # set the vars ...

by 科技牛 - Shell - 2007-07-27 10:09:04 阅读(3789) 回复(2)

今天学习 getopt命令时,用到了[code]ARGS=`getopt -a -o p:P:O:t:l:h -l process:,port:,time:,output:,user:,help -- "$@"`[/code]这里的 -- "$@" 有什么作用? 因为在后面的代码中 while true: do case $1 in -a) func1;shift;; -b) func2;shift;; --) shift;break;; esac shift done 如果没 --)这里 ,这个循环跳不出来!

by tank064 - Shell - 2013-03-01 16:34:16 阅读(1142) 回复(3)

看到好像很多 实际项目 都不使用C库里面的 getopt而是自己实现 类似的函数 是因为 windows下面没有这个函数 还是因为 效率或者其他原因?

by snyh - C/C++ - 2009-10-30 21:12:49 阅读(1925) 回复(7)

1. getopt的作用是用来解析命令行选项,譬如:>mysql -u lvdbing -p test -h 192.168.1.20 2. getopt提供的函数包括:Python 2.6.1+ (r261:67515, Mar 2 2009, 13:11:28) [GCC 4.3.3] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> import getopt >>> getopt.__all__ ['getoptError', 'error', 'getopt', 'gnu_getopt'] >>> 3. 帮助文档的例子:>>> s = '--condition=foo --testing ...

by lvDbing - Python文档中心 - 2009-05-28 21:13:16 阅读(3942) 回复(0)

linux 环境下 [code] stan@stan /temp $ ls -al echo.c -rw-r--r-- 1 stan users 300 2008-07-25 12:00 echo.c stan@stan /temp $ ls echo.c -al -rw-r--r-- 1 stan users 300 2008-07-25 12:00 echo.c [/code] 选项参数放在选项之前貌似也是可以的嘛!以前不都是要求选项参数放在选项之后,是否次序无所谓啊?这个功能是由getopt实现的吗? Thanks

by bcjrstan - C/C++ - 2008-07-28 00:35:46 阅读(1155) 回复(0)

getopt参数好像不能识别错误选项 比如有"abc:d:012" 我运行程序时./cmd -c -d 竞不报错,在shell中是报错的呀 说明已对?作过处理

by chzht001 - C/C++ - 2007-12-05 13:50:31 阅读(1057) 回复(0)

char *svalue=NULL; while((opt=getopt(argc,argv," :ls: ")!=-1)) . . . case 's': svalue=optarg; break; RUN: ./a -s file1 1.问题: 如果我想-s接收的是多个不定的参数请问怎么改呢? 如: -s file1 file2 或 -s file1 file2 file3 2.在书上看 opt=getopt(argc,argv," :ls::k ")!=-1 s后两个"::"表示接收两个参数?还是两个以上的参数呢?

by linuxcici - C/C++ - 2006-08-25 02:07:31 阅读(2421) 回复(4)

我在一本书上看到:如果getopt()找不到符合的参数则会印出错信息,并将全域变量optopt设为“?”字符。 但是程序显示好像不是这样:[code]#include; #include; extern char *optarg; extern int optind, optopt,opterr; int main(int argc,char **argv) { int ch; while((ch = getopt(argc,argv,"a:bcd")) != -1) switch(ch) { case 'a': printf("option a:'%s'\n",optarg); break; case 'b': pr...

by xueyan - C/C++ - 2005-04-20 13:18:03 阅读(977) 回复(2)

如何用getopt 获得这样的结果:ngrep port 5060

by mylover9989 - C/C++ - 2004-11-16 15:22:32 阅读(1253) 回复(6)

#include <stdio.h>
#include <stdlib.h>

by iARM - 移动操作系统 - 2011-02-22 17:46:42 阅读(647) 回复(0)