Skip to main content
Filter by
Sorted by
Tagged with
0 votes
1 answer
81 views

After finding out about getopt (and being disappointed it seems to have to work with eval no matter what, which means function inputs have to be filtered for security), I have nevertheless been using ...
Signor Pizza's user avatar
3 votes
2 answers
107 views

I am running a C program like this: int main(int argc, char **argv) { int opt; // Normal command line parsing while ((opt = getopt(argc, argv, "s")) != -1) printf("...
Fabius Wiesner's user avatar
0 votes
0 answers
116 views

I am trying to make a shell in C. I have made a argument tokenizer which takes a char * string and then should return a char ** string array with all the tokenized strings. Doing this for simple ...
meursault's user avatar
2 votes
1 answer
74 views

I have a script that parses command line arguments after using getopt. The issue is that the -- before my positional arguments is caught by my --usage) case, thus showing usage text erroneously. Is ...
CompSciDude's user avatar
4 votes
1 answer
231 views

I'm trying to catch a missing argument when starting my program. This example is a simple file copy. the correct command line would be: # prog -i in_file -o out_file If the user forgets to enter an ...
sake's user avatar
  • 53
0 votes
1 answer
62 views

Here is my test.sh: #!/usr/bin/env bash arg="default" TEMP=$(getopt --long been: -n 'test.sh' -- "$@") eval set -- "$TEMP" while true ; do case "$1" in ...
showkey's user avatar
  • 505
1 vote
1 answer
160 views

Show bash and getopt version in my OS: bash --version |grep [r]elease GNU bash, version 5.2.15(1)-release (x86_64-pc-linux-gnu) getopt --version getopt from util-linux 2.38.1 In the getopt's manual(...
showkey's user avatar
  • 505
9 votes
1 answer
282 views

So, man page says getopt() takes char * const argv[], which is an array of constant pointers to char, as far as I understand. At the same time, getopt() permutes argv, so that eventually all non-...
leschtsch's user avatar
  • 103
2 votes
2 answers
143 views

I'm trying to implement an option handling similar to FFmpeg. Specifically, I want to support two types of palette options: Direct palette specification: -p "255,0,0 0,255,0" Config file ...
N00B_141's user avatar
0 votes
1 answer
89 views

In getopt(3) on both FreeBSD and macOS, it states (emphasis mine): It is also possible to handle digits as option letters. This allows getopt() to be used with programs that expect a number ("-...
Paul J. Lucas's user avatar
0 votes
0 answers
101 views

I am trying to pass arguments to my process: (Product (int), Timestamp (std::string), LPN (std::string), Class (int) and State (int)). I want to execute my process like this: ...
user25614722's user avatar
1 vote
1 answer
131 views

This has been driving me crazy for a while cause it was working fine before on Ubuntu until I upgraded to Ubuntu 23.10. I'm calling the getopt() function in C without any loop and only once in the ...
Richard Ore's user avatar
1 vote
1 answer
215 views

I am working on a simple decimal to hex/binary calculator that will take command line arguments to specify which to convert to, -x for hex and -b for binary. I am using getopt() to parse in values. I ...
OneBallRyan's user avatar
2 votes
2 answers
110 views

I'm trying to write a program that has an option that takes an optional argument, in such a way that it accepts options in the same fashion with the exact same behavior as perl -i or git --color. ...
Darren Embry's user avatar
1 vote
2 answers
267 views

I have getopt from util-linux 2.38 on my system: [davide@68YM9C3 tmp]$ getopt -V getopt from util-linux 2.38 [davide@68YM9C3 tmp]$ I would like to have an optional parameter to a long option but I ...
louigi600's user avatar
  • 753
1 vote
1 answer
117 views

A C program I am writing takes files and flags as arguments. The program needs to support flags being placed anywhere amongst the arguments. So, for example, "./program file1 file2 -f 10 file3 ...
Boosen's user avatar
  • 29
3 votes
3 answers
3k views

I'm writing a simple Bash script that requires argument parsing and have composed the following script that uses getopt to parse short or long arguments provided to the script. #!/bin/bash # Default ...
Anil's user avatar
  • 1,459
0 votes
2 answers
160 views

I'm trying to write some code that will tie together a series of conda tools and a bit of my own python code. I've provided some getopt options, but they parse weirdly. I'd like options to be able to ...
schmiggle's user avatar
0 votes
1 answer
74 views

Code: import getopt import sys print("Let's read the arguments from command line") user_inputs = sys.argv[1:] print(user_inputs) # get option and value pair from getopt try: opts, ...
nnay84's user avatar
  • 177
0 votes
0 answers
99 views

getopt utility in macOS is not respecting or not allowing space character while passed with a string argument. Below is sample script #!/bin/bash TEMP=$(getopt -n "$0" -a -l "project:&...
James Taylor's user avatar
-2 votes
1 answer
68 views

I'm trying to get the arguments by using getopt import sys import getopt import time from datetime import timedelta start_time = time.monotonic() filename = '' startIndex = 1 debug = False outputFile =...
user426132's user avatar
  • 1,451
0 votes
0 answers
42 views

Consider the following script called mwe.sh: #!/usr/bin/env bash o() { printf "DEBUG: o: executing...\n" printf "DEBUG: o: args: %s\n" "$*" local ...
leo's user avatar
  • 141
0 votes
1 answer
159 views

I am typing up a program and it takes three command-line options: s, f and c Since I was told to use getopt() as a function to get them, I looked into it. The three options do the following: s - this ...
DarkRemino's user avatar
0 votes
1 answer
197 views

Im trying to get an int from the optarg from the c modifier in my code, but i can't get to it, I tried to cast it but it wasn't possible, so I investigated and found this atoi() function suposed to ...
Nicolás Marcelo's user avatar
0 votes
2 answers
98 views

So, I have next code: #include<unistd.h> #include<getopt.h> #include<getopt.h> #include<stdio.h> #include<stdlib.h> #include<errno.h> #include<string.h> // #...
Vladyslav Rehan's user avatar
1 vote
1 answer
100 views

this is a code for chunk.c file which divides a large file (filename.txt) into smaller chunked files by lines. #include <stdio.h> #include <stdlib.h> #include <string.h> #include <...
springbook's user avatar
2 votes
1 answer
130 views

I am very new to running perl scripts and I am running into problems that I suspect are due to the assignment of variables. Here is the beginning of the original script: #!/usr/bin/perl -w ###########...
Froggy01's user avatar
0 votes
0 answers
98 views

I build a doubly linked list which orders strings in alphabetical order as you add them. The strings come from an input file and I use getopt to get the input file from the command line. When i test ...
Luis V's user avatar
  • 1
3 votes
1 answer
2k views

I have the following command: command.sh bar -b=FOO I'm trying to parse it with the following: getopt "m::b::" "$@" Under Linux, the result is: -b =FOO -- command.sh bar Under ...
Alexander  Pravdin's user avatar
0 votes
0 answers
51 views

I want to be able to support commands such as: ./myProgram -f required_arg1 -v required_arg2 and ./myProgram -fv required_arg1 required_arg2 Where required_arg1 belongs to -f and required_arg2 ...
Tyler's user avatar
  • 73
0 votes
1 answer
92 views

According to the man page for getopt and getopt_long, the GNU version reorders argv so that anything resembling a flag will be first, then it will return -1 when it reaches the first string that is ...
eternallymisty's user avatar
2 votes
1 answer
746 views

I've been reading Head First C and I'm currently stuck at understanding int main(int argc, char *argv[]) and the optind variable of getopt(). I'm troubled by the same program as the one in How does &...
NoobAdmin's user avatar
1 vote
1 answer
392 views

The Unix man page for getopt states If there are problems parsing the parameters, for example because a required argument is not found or an option is not recognized, an error will be reported on ...
Lawrence I. Siden's user avatar
0 votes
1 answer
53 views

I'm currently trying to set up my machine learning experiment to use Bash long options for Python arguments but am getting a parsing error. My script looks like this: #! /usr/bin/bash ...
Sean's user avatar
  • 3,470
0 votes
1 answer
349 views

I'm trying to make the getopt to optionally accept an argument. For example, based on the code below: #!/bin/bash short_opts="e:" options=$(getopt -o "${short_opts}" -- "$@&...
Kalib Zen's user avatar
  • 1,015
0 votes
0 answers
60 views

I want to create a programme that will have mandatory option and optional option. Mandatory: -d <device> Optional: -h : help -m <value> : launch an internal function with the value of ...
eone's user avatar
  • 1
-1 votes
1 answer
99 views

I'm starting a new project in C++, I started by creating a function that handles command line arguments using getopt, but it doesn't seem to be working. I'm afraid it is a small mistake, but I've been ...
Pedro Vieira's user avatar
0 votes
0 answers
24 views

here is my code down below, the code is incomplete, but the problem is I have set the t as the only option I have for this program, and when i run it with option -t input, it gives me error as ...
yuchen liu's user avatar
0 votes
1 answer
826 views

how to use long options via getopt_long: for example like this: --wide-option I have --wide and -w. And on --wide-option it gives the following error: "unrecognized option" int main(int ...
Kuttubek's user avatar
0 votes
0 answers
129 views

My case at hand An overgrown one-liner with 10 -sswitch-powered arguments, that I desire to put into a file script whith /usr/bin/env-powered shebang. 10 arguments make me wish for a straightforward ...
Veraellyunjie's user avatar
0 votes
2 answers
89 views

I am working on a c project, which I am trying to write a program that allows users to use one of the command line options to invoke the program. For example ./program [-a or -b or -c] [-f filename] [-...
John Doe's user avatar
0 votes
1 answer
85 views

I am running a script in the ubuntu terminal and it works fine. ./run_script2.sh -b ./exercises/13_caching.py I want to run the same script in python os or subprocess but I am getting an error : ./...
Nagmat's user avatar
  • 372
0 votes
2 answers
179 views

I am trying to compare options that can be entered on the command line for my program. for option f a user can enter c or b. int main(int argc, char** argv){ char *i; char *o; char *f; ...
user2355903's user avatar
4 votes
1 answer
13k views

I am trying to use getopt to parse command line options passed by the user of the program. I am specifically struggling with how to save the "option arguments" that are passed with flag, for ...
user2355903's user avatar
0 votes
2 answers
344 views

UPDATE: After playing the with the code, the answer appears to be changing shift 1 ;; to shift 2 ;; below the input. I'm not a BASH guru so I will leave a few days for someone to post a better answer. ...
Ashenwraith's user avatar
0 votes
2 answers
874 views

I am creating a C program in CentOS linux, and I cannot get my getopt to recognize arguments from the command line. I am relatively new to linux and C. The error I get is 'command not found' I ...
AndrewScott's user avatar
1 vote
1 answer
53 views

I am trying to get options via getopt. I`ve run the program via the command line: test.exe -ja 1:2 -ja 3:4 My code have following: int c; while ((c = getopt (argc, argv, "j:")) != -1) { ...
sasha's user avatar
  • 35
0 votes
1 answer
256 views

I have a script that takes two arguments using sys and getopt module. The issue I am having is that when using shortopts to test that the arguments are being passed correctly, the short option for the ...
lordvue's user avatar
  • 11
0 votes
1 answer
85 views

I don't understand why optopt is zero in my code when an option is recognized but is right when it goes to the '?'case. This is the code: ... int opt; while((opt = getopt(argc, argv, OPZIONI))!= -...
Lorenzo's user avatar
0 votes
1 answer
309 views

int res = 0; while ((res = getopt(argc, argv, "ivlcne")) != -1) { switch (res) { case 'i': pCurrentFlags->i = 1; break; case 'v': pCurrentFlags-&...
The Dolaxom's user avatar

1
2 3 4 5
15