getopt

Perl Getopt::Long Related Question - Mutually Exclusive Command-Line Arguments

北慕城南 提交于 2019-12-23 13:12:02
问题 I have the following code in my perl script: my $directory; my @files; my $help; my $man; my $verbose; undef $directory; undef @files; undef $help; undef $man; undef $verbose; GetOptions( "dir=s" => \$directory, # optional variable with default value (false) "files=s" => \@files, # optional variable that allows comma-separated # list of file names as well as multiple # occurrenceces of this option. "help|?" => \$help, # optional variable with default value (false) "man" => \$man, # optional

“for i” without “in [sequence]” ending while using getopt

落花浮王杯 提交于 2019-12-21 13:01:26
问题 I've found example script for using getopt command in shell. #!/bin/bash args=$(getopt ab $*) set -- $args for i; do case "$i" in -a)shift; echo "it was a";; -b)shift; echo "it was b";; esac; done It work well, but I don't understand where is variable $i assigned. How it knows that it must iterate through $arg. Can you explain this? 回答1: As shown here, for defaults to $@ if no in seq is given. The for i assigns your $i variable. 来源: https://stackoverflow.com/questions/16102089/for-i-without

Can OptionParser skip unknown options, to be processed later in a Ruby program?

与世无争的帅哥 提交于 2019-12-21 03:42:46
问题 Is there any way to kick off OptionParser several times in one Ruby program, each with different sets of options? For example: $ myscript.rb --subsys1opt a --subsys2opt b Here, myscript.rb would use subsys1 and subsys2, delegating their options handling logic to them, possibly in a sequence where 'a' is processed first, followed by 'b' in separate OptionParser object; each time picking options only relevant for that context. A final phase could check that there is nothing unknown left after

Getopt optional arguments?

北战南征 提交于 2019-12-19 06:01:31
问题 I have a program where you enter an option -d and then whether or not you supply a non-optional argument after the option, do something. Heres my code: #include <stdio.h> #include <getopt.h> #include <stdlib.h> #define OPT_LIST "d::" int main (int argc, char *argv[]) { int c; char string[] = "blah"; while ((c = getopt (argc, argv, OPT_LIST)) != -1) { switch (c) { case 'd': printf("%s\n", optarg); break; case '?': fprintf(stderr, "invalid option\n"); exit(EXIT_FAILURE); } } } So if you enter a

using getopt with gdb

社会主义新天地 提交于 2019-12-19 03:19:17
问题 have just incorporated getopt into my main() func getopt sets the global variable optarg for each call stepping through main() with gdb , after getopt() call optarg is always NULL (e.g. (gdb) p optarg ) yet printf("%s\n", optarg) outputs the cmd line arg as expected whats going on? why are the two not the same? Is this an isue with gdb and how it trys to inspect globals or is something else going on? 回答1: Probably related: Bug 13800 - gdb does not print right values of getopt-related values

Getopt- Passing string parameter for argument

梦想的初衷 提交于 2019-12-18 10:26:26
问题 I have a program which takes in multiple command line arguments so I am using getopt. One of my arguments takes in a string as a parameter. Is there anyway to obtain that string through the getopt function or would I have to obtain it through the argv[] array? Also can getopt read args like -file ? All the arguments I have seen till now have only one character such as -a EDIT From the below answers I have written a program to use getopt_long(), but the switch statement only recognizes the

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

安稳与你 提交于 2019-12-17 03:32:32
getopt 与 getopts 都是 Bash 中用来获取与分析命令行参数的工具,常用在 Shell 脚本中被用来分析脚本参数。 两者的比较 (1)getopts 是 Shell 内建命令,getopt 是一个独立外部工具 (2)getopts 使用语法简单,getopt 使用语法较复杂 (3)getopts 不支持长参数(如: --option ),getopt 支持 (4)getopts 不会重排所有参数的顺序,getopt 会重排参数顺序(这里的区别下面会说明) (5)getopts 出现的目的是为了代替 getopt 较快捷的执行参数分析工作 1 getopts #!/bin/bash while getopts 'd:Dm:f:t:' OPT; do case $OPT in d) DEL_DAYS="$OPTARG";; D) DEL_ORIGINAL='yes';; f) DIR_FROM="$OPTARG";; m) MAILDIR_NAME="$OPTARG";; t) DIR_TO="$OPTARG";; ?) echo "Usage: `basename $0` [options] filename" esac done shift $(($OPTIND - 1))    getopts后面的字符串就是可以使用的选项列表,每个字母代表一个选项,后面带

Python日志监控(发音版)

房东的猫 提交于 2019-12-17 00:37:24
前段时间有朋友让帮忙做一个日志监控的脚本,要求如下: 1.windows环境 2.当匹配日志关键字时会发出声音,匹配的关键字不同,播放的声音不同 3.能做到实时响应 于是从网上找了个windows版的 tail ,使用python简单写了个小脚本,代码如下: #!/usr/bin/env python# encoding: utf-8"""MonitorLog.pyUsage: MonitorLog.py ...Monitor the log file-f log file-h help infopython MonitorLog.py -f C:\monitor.logCreated by zhoubo on 2011-08-29."""import sysimport osimport getoptimport subprocessimport timeimport codecsimport winsoundABSPATH = os.path.dirname(os.path.abspath(__file__))MONITERCONF = 'moniter_keyword.txt' #utf8 filedef main(): try: opts, args = getopt.getopt(sys.argv[1:], 'hf:') except getopt.GetoptError

looking for best way of giving command line arguments in python, where some params are req for some option and some params are req for other options

前提是你 提交于 2019-12-13 04:30:48
问题 Hi i am trying to send command line arguments for first time. The condition is that one parameter is required for one option and for others other parameter.(looking for user friendly). The below code looks need some optimization: import argparse parser = argparse.ArgumentParser(description='Usage options.') parser.add_argument('-o','--options',help='Options available: run,rerun,kill, resume, suspend',required=True) parser.add_argument('-c', '--config',help='config file input',type=file

Calling different programs with different options and different arguments for each option

十年热恋 提交于 2019-12-13 03:11:24
问题 I am trying to make a script that can execute a different number of programs simultaneously (prog1, prog2,...prog5, or even more). It can be prog1 only , or prog1&prog2, or prog1&prog2&prog3, prog1&prog3&prog4&prog6&prog8 Each program can be called with different options and will execute different things depending on it's calling options. For instance prog1 can be called in these different ways: prog1 -d "-f 10 -g 20" (-d is an option and "-f 10 -g 20" arguments for that specific option)