Questions tagged [getopt]

The `getopt` and `getopt_long` functions automate some of the chores involved in parsing typical unix command line options.

The getopt and getopt_long functions automate some of the chores involved in parsing typical unix command line options.

For details, please read here.

717 questions
12
votes
5 answers

linux GNU getopt: ignore unknown optional arguments?

Is it possible to ignore unknown optional arguments with GNU getopt? I have a script, scriptA.sh, that has optional arguments --optA, --optB, --optC, --optD. I would like to write a wrapper, wrapperA, with two optional arguments, --optX and --optY,…
user3830744
  • 131
  • 1
  • 5
11
votes
1 answer

Specify long command line arguments without the short format getopt

Let's say I provide the following long option arguments structure: static const struct option long_opts[] = { { "version", no_argument, NULL, 'v' }, { "help", no_argument, NULL, 'h' }, { NULL, 0, NULL, 0 } }; How can…
kaspersky
  • 3,959
  • 4
  • 33
  • 50
11
votes
2 answers

Getopt- Passing string parameter for argument

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…
RagHaven
  • 4,156
  • 21
  • 72
  • 113
10
votes
5 answers

How do I access argv / command line options in Dart?

And does Dart have a getopt library?
mcandre
  • 22,868
  • 20
  • 88
  • 147
10
votes
1 answer

Using getopt() in C++ to handle arguments

The program works like this, argument is supplied in a form like this at the beginning: -w cat The string "cat" is stored in variable pattern and for each letter that is followed by - we do something; in this case we set mode = W. What I have…
user9111757
10
votes
2 answers

Optional command line arguments

Given code like this, how do I actually set a file in the run options? I am using Spyder and have put -h -s -p -o as arguments, but I'm not sure how to specify a named file for the -o option. class CommandLine: def __init__(self): opts,…
user1893110
  • 241
  • 1
  • 3
  • 12
10
votes
4 answers

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…
Rachel
  • 100,387
  • 116
  • 269
  • 365
10
votes
4 answers

How can I set default values using Getopt::Std?

I am trying to collect the values from command line using Getopt::Std in my Perl script. use Getopt::Std; $Getopt::Std::STANDARD_HELP_VERSION = 1; getopts('i:o:p:'); my $inputfile = our $opt_i; my $outputfile = our $opt_o; my $parameter_value = our…
Suren
  • 173
  • 2
  • 4
  • 10
10
votes
1 answer

Is it possible to repeat getopt

I'm trying to create a basic shell with builtin commands, and I'm having some issues with getopt. Here is the output (using valgrind): $ mkdir -p foo/bar mkdir -p foo/bar FLAGON $ mkdir -p foo/test mkdir -p foo/test ==15377== Invalid read of size…
MiJyn
  • 5,327
  • 4
  • 37
  • 64
9
votes
4 answers

getopt value stays null

I am passing my program inputs and I could see them in argv but getopt doesnt seem to have the argument that I expect. This is how I run my prog: ./my_prog -X -f filename while ((opt = getopt(argc, argv, "Xf:eE:dD")) != EOF) { switch…
hari
  • 9,439
  • 27
  • 76
  • 110
9
votes
1 answer

How does "optind" get assigned in C?

I am creating this question because there is not much about how this optind gets assigned for each loop. Man page says : The variable optind is the index of the next element to be processed in argv. The system initializes this value to 1. Below, I…
Burak Kaymakci
  • 662
  • 2
  • 16
  • 36
9
votes
1 answer

Why cant I have a space between option and optional argument using getopt?

When using getopt to parse commandline parameters you can put a space in between the option flag and the argument for required arguments but not for optional arguments. Optional arguments will only be parsed if they are right after the…
pdizz
  • 4,100
  • 4
  • 28
  • 42
9
votes
4 answers

How to get a value from optarg

Hi I am writing a simple client-server program. In this program I have to use getopt() to get the port number and ip address like this: server -i 127.0.0.1 -p 10001 I do not know how can I get values from optarg, to use later in the program.
Mateusz
  • 853
  • 4
  • 12
  • 19
9
votes
2 answers

What is the "POSIX-defined format" for command-line error messages? Which standard?

On ruby-doc.org page I found the following about command-line options/arguments parsing (getopt library): Return the appropriate error message in POSIX-defined format. If no error has occurred, returns nil. What is POSIX-defined format for…
Vladimir Keleshev
  • 13,753
  • 17
  • 64
  • 93
9
votes
3 answers

which library to use to parse command line arguments in C++

I know about getopts and argp. I just looked in boost and they have program_options as a library for parsing command-line parameters. I'm not exactly sure which one to use. I know getopts is POSIX, while argp isn't but that doesn't matter to me.…
s5s
  • 11,159
  • 21
  • 74
  • 121
1 2
3
47 48