getopt

How to call getopts in bash multiple times...

I have a common library that I use from several scripts that parses command line options, however I also want my individual scripts to be able to process arguments as well... e.g. common.sh: function get_options { echo -e "in getoptions" echo $OPTIND while getopts ":ab:" optionName; do [ ... processing code ... ] ...

getopt_long vs getopt_long_only

Hi guys, to do a proper Linux/unix styled application, what is the best choice (eg. afaik ls uses getopt_long but for example ffmpeg getopt_long_only). Which one do you recommend? Cheers, ...

Using getopt to parse program arguments in c++

I have a program which takes various command line arguments. For the sake of simplification, we will say it takes 3 flags: -a, -b, and -c and use the following code to parse my arguments int c; while((c = getopt(argc, argv, ":a:b:c")) != EOF) { switch (c) { case 'a': cout << ...

PHP getopt Operations

This question is regarding getopt function in php. I need to pass two parameter to the php scripts like php script.php -f filename -t filetype Now depending upon the file type which can be u, c or s I need to do proper operation. I am using switch case for the same: Here is the Code I am using: // Get filename of input file when e...

How to process python generated error messages my own way?

For some code as follows, opts, args = getopt.getopt(sys.argv[1:], "c:", ... for o,v in opts: ... elif o in ("-c", "--%s" % checkString): kCheckOnly = True clientTemp = v If I don't give the parameter after the -c, I get the error messages as follows. Traceback (most recent call last): File...

Cross-platform getopt for a shell script

I've just found out that getopt is not cross-platform (in particular for FreeBSD and Linux). What is the best workaround for this issue? ...

How to handle main option with Getopt

I want to handle a feature which seems to me almost natural with programs, and I don't know how to handle it with Getopt perl package (no matter Std ot Long). I would like something like: ./perlscript <main option> [some options like -h or --output-file some_name] Options will be handled with - or --, but I want to be able to let the...

How can I allow undefined options when parsing args with Getopt

If I have a command line like: my_script.pl -foo -WHATEVER My script knows about --foo, and I want Getopt to set variable $opt_foo, but I don't know anything about -WHATEVER. How can I tell Getopt to parse out the options that I've told it about, and then get the rest of the arguments in a string variable or a list. An example: use...

Why use argparse rather than optparse?

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 their new features I should know about? ...

C getopt -<integer>

How do I get the option -10 from command line arguments- "tail -10". getopt function finds '1' character. But how do I access the string "10"? If this can be done by getopt_long, an example would help. Thanks. ...

Perl Getopt Configure Issues

#test.pl use Getopt::Long; Getopt::Long::Configure ("bundling"); GetOptions ( 'TestB|B|b' => \$testb , 'TestA|A|a' => \$testa, ); Here is my situation i may exute perl test.pl -Ba so i use Getopt::Long::Configure ("bundling"); Because of this my program is getting slowed initally even i tryed to execute with options ...

Can optparse skip unknown options, to be processed later in a ruby program?

Is there any way to kick off optparse several times in one Ruby program, each with different sets of options? 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 s...

Pass zero in to Getopt::Std

Hi I am using Getopt::Std in a Perl script, and would like to pass in a zero as value. I am checking that values are set correctly using unless(). At the moment unless() is rejecting the value as being unset. Is there a way to get unless() to accept zero as a valid value (any non-negative integer is valid). This is probably perfeclty ...

getopt - parameters that aren't flags?

I'm trying to use the getopt function for the first time only I'm having problems with arguments that aren't flags. For instance, in my code when a unknown argument is given I want to use it as a input file. When I run this with only a file name it is not printed, if I first use a flag, any flag, then I can print it. How can I fix this?...

Java boolean CLI options

I'm getting my feet wet with the Apache Commons CLI library for command-line parsing. It works fine for String-valued options, but I'm not sure how to cleanly handle boolean-valued command-line flags. I've tried this: CommandLineParser parser = new GnuParser(); Options options = new Options(); options.addOption(new Option(...

Do you have a good Perl template script?

I do a lot of programming in Perl and was wondering if people had a "default" template Perl script that they use and willing to share. I started copying one of my older scripts which has Getopt functions. I am thinking people would have done something similar? ...

Parsing command line arguments in a python script (getopt woes)

Ok, python newbie here. This is so elementary, I am almost embarrassed to post the question - yet still, I have spent more than a few minutes trying to get it to work - time to swallow my pride. Here is the script. Can anyone spot why it is not printing the passed arguments? import sys, getopt def usage(): print 'Unknown argument...

C getopt multiple value

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 jusst the file1, how to get file2, file 3 ?? Thanks in advance ...

How to make a multi-character parameter in UNIX using getopt?

I'm trying to make a getopt command such that when I pass the "-ab" parameter to a script, that script will treat -ab as a single parameter. #!/bin/sh args=`getopt "ab":fc:d $*` set -- $args for i in $args do case "$i" in -ab) shift;echo "You typed ab $1.";shift;; -c) shift;echo "You typed a c $1";shift;; esac done How...

In Unix, is it possible to give getops a range of values to expect?

Sorry if the title is confusing, but here's what I mean: If I have a script that can accept several parameters, I'd use the getops command in order to more easily control script actions based on the parameters passed. However, lets say one of these parameters can be any number from 5 - 9, or whatever. Is there a way to tell getops that ...