Questions tagged [getopt-long]

Getopt::Long is a command line switch parsing library for Perl. For C-programming: The getopt and getopt_long functions automate some of the chores involved in parsing typical unix command line options.

The Getopt::Long Perl module is a parser for the POSIX command line switch syntax with GNU extensions. Both the traditional -s single character switches and the longer --longer switches are supported.

For C-programming: The getopt and getopt_long functions automate some of the chores involved in parsing typical unix command line options. For details, please see here.

190 questions
1
vote
1 answer

Using Get Options and Pod Usage in Perl

I'm trying to edit a Perl program to use the Get Options and Pod Usage modules. When I try to do so it seem to break it. The first code sample is the original file that works and the second code sample is the edited version that does not work. …
Zenneson
  • 27
  • 7
1
vote
1 answer

Perl: store multi-valued cmd line argument directly into hash keys

I'm adding some command line parsing to a Perl script and I'm trying to figure out how to store the multiple values of a single command line argument as keys of a hash. The following MWE hopefully gets at what I want to do. # foo.pl use…
SSilk
  • 2,433
  • 7
  • 29
  • 44
1
vote
2 answers

when long option is given as argument to short option - getopt_long

I was learning how to accept command line arguments using getopt_long function, I made 2 long options 'filename' (required arg) and 'clear' (no arg) and 2 short args 'a' (with arg) and 'b' (no arg) when i executed: $ ./a.out -a…
Anup Agarwal
  • 53
  • 1
  • 8
1
vote
2 answers

getopt with repeated and optional arguments

For a simple C project of a filesystem in a file, I have to make a command for writing the partitions table. It just contains the number of partitions and the size of them, pretty simple. It should work like mk_part -s size [-s size ...]…
user3593232
  • 111
  • 1
  • 3
1
vote
1 answer

getopt_long not working as expected

I have the following code #include #include int main(int argc, char* argv[]){ const struct option longopts[]={ {"one", required_argument, 0, '1'}, {"two", required_argument, 0, '2'}, …
Abhishek Choubey
  • 883
  • 6
  • 16
1
vote
1 answer

Getopt::Lazy does not print usage message or anything else

I need some help using perls Getopt::Lazy module. I tried the example from the cpan page: #!/usr/bin/perl # #use warnings; #use strict; use Getopt::Lazy 'help|h' => 'Show this help screen', 'verbose|v' => 'Show verbose output', …
Isaac
  • 810
  • 2
  • 13
  • 31
1
vote
1 answer

how to use getopt to parse one option only once

i want to parse one option ONLY ONCE and make it skip or make an error when there are two different options that conflict each other entered in argument. for example, ./a.out --install --remove //i dont want this to work... i was thinking of…
hoholee12
  • 334
  • 3
  • 14
1
vote
1 answer

How to write getopt in bash script

I have a function with a few parameters. For example: makeUser{ login email password} I want to make flags like -l|--login, -e|--email and -p|--password but I don't know how. The sample for it should look like the code below: ./script.sh --mode…
adamos
  • 69
  • 8
1
vote
5 answers

GetOptions Check Option Values

I am updating an existing Perl script that uses GetOptions from Getopt::Long. I want to add an option that takes a string as its parameter and can only have one of 3 values: small, medium, or large. Is there any way to make Perl throw an error or…
Samuel
  • 8,063
  • 8
  • 45
  • 41
1
vote
2 answers

How should you declare flag-dependent variables using Getopt::Long in perl?

I am using Getopt::Long to parse command line flags and arguments for a perl script. For certain flags, I need to declare to variables within the script that are only used if that flag has been selected - otherwise they're never used. I want to…
jms
  • 172
  • 1
  • 8
1
vote
1 answer

Segfault for invalid long option

I have the following code: struct option longopts[] = { {"version", no_argument, 0, 'v'} }; if (argc > 1) { int c; int longindex; while ((c = getopt_long (argc, argv, "v", longopts, &longindex)) != -1) { switch…
2mac
  • 1,609
  • 5
  • 20
  • 35
1
vote
2 answers

Passing multiple file lists to perl script

I want to pass two file lists to my perl script and have them handled with Getopt::Long for storing an array (via a reference) in a dictionary. #!/usr/bin/env perl # author:sb2 use strict; use warnings; use Getopt::Long; use File::Basename; use…
s_boardman
  • 416
  • 3
  • 9
  • 27
1
vote
1 answer

How to pass escape sequence like tab and newline char as command line argument in C programming getopt_long?

I almost reached end of my code, after a lot of search I didn't find solution no where, I want to supply escape sequence like '\t', '\n' to my program like how awk and perl program takes, and finally I want to use them as printf or sprintf format…
user3637224
  • 585
  • 1
  • 3
  • 22
1
vote
1 answer

Trying to use getopt to parse input in c

Ok, so basically I am looking for a number following inputs a and b and I'm searching for c and d without requiring additional info. When I try to do this using getopt, however, my loop never executes. Here is some example code: int aa = 0; int av…
dashiz
  • 41
  • 4
1
vote
1 answer

perl getoptions multiple values

I am trying to parse command line options and values in my script. The script accepts 2 options: updategroup or validategroup. The updategroup option should accept 2 values. For example: ./script.pl -updategroup 'group1' 'enable' This is how I…