getopt

C getopt multiple value

寵の児 提交于 2019-11-26 12:43:00
问题 My argument is like this ./a.out -i file1 file2 file3 How can I utilize getopt() to get 3 (or more) input files? I\'m doing something like this: while ((opt = getopt(argc, argv, \"i:xyz..\"))!= -1){ case \'i\': input = optarg; break; ... } I get just the file1 ; how to get file2 , file3 ? 回答1: If you must, you could start at argv[optind] and increment optind yourself. However, I would recommend against this since I consider that syntax to be poor form. (How would you know when you've reached

getopt.h: Compiling Linux C-Code in Windows

扶醉桌前 提交于 2019-11-26 10:58:07
问题 I am trying to get a set of nine *.c files (and nine related *.h files) to compile under Windows. The code was originally designed in Linux to take command line arguments using the standard GNU-Linux/C library \"getopt.h\". And that library does not apply to building the C-code in Windows. I want to ignore what my code does right now and ask the following question. For those of you familiar with this C-library \"getopt.h\": will it be possible to build and run my code in Windows if it depends

Optional option argument with getopts

非 Y 不嫁゛ 提交于 2019-11-26 09:09:12
问题 while getopts \"hd:R:\" arg; do case $arg in h) echo \"usgae\" ;; d) dir=$OPTARG ;; R) if [[ $OPTARG =~ ^[0-9]+$ ]];then level=$OPTARG else level=1 fi ;; \\?) echo \"WRONG\" >&2 ;; esac done level refers to parameter of -R , dir refers to parameters of -d when I input ./count.sh -R 1 -d test/ it works rightly when I input ./count.sh -d test/ -R 1 it works rightly but I want to make it work when I input ./count.sh -d test/ -R or ./count.sh -R -d test/ This means that I want -R has a default

Why use argparse rather than optparse?

依然范特西╮ 提交于 2019-11-26 04:32:02
问题 I noticed that the Python 2.7 documentation includes yet another command-line parsing module. In addition to getopt and optparse we now have argparse . Why has yet another command-line parsing module been created? Why should I use it instead of optparse ? Are there new features that I should know about? 回答1: As of python 2.7 , optparse is deprecated, and will hopefully go away in the future. argparse is better for all the reasons listed on its original page (https://code.google.com/archive/p

shell 命令行参数(getopt和getopts)

ぃ、小莉子 提交于 2019-11-26 02:31:02
这里还有上一篇,这部分是基础: https://blog.51cto.com/steed/2443313 getopt 命令 使用getopt命令,可以解析任何命令行选项和参数,但是用法比较复杂。getopt的命令用法如下: $ getopt --help 用法: getopt optstring parameters getopt [options] [--] optstring parameters getopt [options] -o|--options optstring [options] [--] parameters 选项: -a, --alternative 允许长选项以 - 开始 -h, --help 这个简短的用法指南 -l, --longoptions <长选项> 要识别的长选项 -n, --name <程序名> 将错误报告给的程序名 -o, --options <选项字符串> 要识别的短选项 -q, --quiet 禁止 getopt(3) 的错误报告 -Q, --quiet-output 无正常输出 -s, --shell <shell> 设置 shell 引用规则 -T, --test 测试 getopt(1) 版本 -u, --unquoted 不引用输出 -V, --version 输出版本信息 $ 用法一共有3种格式,下面都会用到。

Using getopts to process long and short command line options

♀尐吖头ヾ 提交于 2019-11-25 21:53:59
问题 I wish to have long and short forms of command line options invoked using my shell script. I know that getopts can be used, but like in Perl, I have not been able to do the same with shell. Any ideas on how this can be done, so that I can use options like: ./shell.sh --copyfile abc.pl /tmp/ ./shell.sh -c abc.pl /tmp/ In the above, both the commands mean the same thing to my shell, but using getopts , I have not been able to implement these? 回答1: There are three implementations that may be