Skip to main content
The 2024 Developer Survey results are live! See the results

Questions tagged [options]

Passing options like -l or --word to commands, or parsing them in scripts.

-1 votes
1 answer
48 views

Parsing `-C8` to get value to option -C

I want to parse -C8 to a bash function and get the numeric value in a variable. I have seen argument parsing implementations for -C 8 and -C=8, but not for -C8. while (( $# > 0 )); do case $1 ...
Vera's user avatar
  • 1
1 vote
2 answers
81 views

What is the reasoning behind accepting truncated long command line options?

Many command line utilities accept long ("GNU style", according to [1]) options such as --version. To my surprise, truncated versions are often interpreted as the full option. For example, ...
Mårten W's user avatar
  • 119
0 votes
2 answers
136 views

Exit while loop when reaching last positional argument

I want to adapt this so that when the function reaches the last positional argument, the while condition exits. console_codes () { local exec=0 local narg="$#" iarg=0 while (( narg > 0 ...
Vera's user avatar
  • 1
2 votes
1 answer
79 views

Dealing with simple help option far bash function

I have adapted some code I had to handle just a single possible option. Either run the function or use the help option to give a brief description. activate-jet () { local iarg=0 narg="$#&...
Vera's user avatar
  • 1
0 votes
1 answer
2k views

getopt optional argument with optional value

I am using getopt and want to have an option -l that takes an optional value. I am finding that when matching -l by itself with no argument value provided, I still have to use shift 2 rather than ...
Vera's user avatar
  • 1
4 votes
3 answers
1k views

Looping through command line parameter options until next parameter

In a new addition to a script I am working on, I want to loop through parameters associated with a flag until zsh reaches the next flag in the command. For instance, when the user enters the following:...
Karie's user avatar
  • 53
-1 votes
1 answer
169 views

ls -l | cut -c1-11,50- Can Someone Explain the 2nd part after the pipe?

I have taken a course in that suddenly I saw this, I understood until the pipe but the options used after the pipe for the command cut are bit confusing
Matta Rithik Reddy's user avatar
-1 votes
1 answer
72 views

Is it OK if I add a duplicated option when calling an alias for rm?

I have alias rm='rm -i' in .bashrc. Now, if I use rm -i by mistake, it will become rm -i -i. Would anything go wrong because of two same options?
Wade Wayne's user avatar
0 votes
2 answers
6k views

Can you make a bash script's option arguments be optional?

I would like either of these inputs to work. That is, the -n option itself is optional – I already know how to do that – but it then may have an optional parameter on top. If no parameter is given, a ...
WoodrowShigeru's user avatar
0 votes
0 answers
302 views

difference between environment variables and parsing command line options?

Am I wrong in assuming that both environment variables serve similar purposes - to modify default behaviour of a program from the shell? When writing a program in C, for example, if I am faced with ...
First User's user avatar
0 votes
1 answer
291 views

Setting verbosity level from list of function arguments

I am using a bash function to which I pass arguments. I would like to capture if a particular option was defined by the user -v NUM or --verbosity=NUM. If defined as described, I would like to set ...
Isabel's user avatar
  • 79
2 votes
4 answers
1k views

When are grouped parentheses for multiple options necessary?

I am using the find and grep commands. Getting quite confused about when multiple options are joined by "or" with the -o flag and the use of grouped parentheses, and when grouped parentheses ...
Pietru's user avatar
  • 393
0 votes
0 answers
95 views

Removing delimiters from bash array elements, then transferring result to another array

I am using an option variable array incl that stores filename extensions. ("--incl") local incl+=("$2") ; shift 2 ;; The function can then be called using --incl .texi --...
Pietru's user avatar
  • 393
0 votes
0 answers
148 views

Handling Optional Arguments in bash

I have the following function that is supposed to write strings in new lines. There is a warning option, so that when -w is set by the user, some lines get coloured in red. -w allows an optional ...
Pietru's user avatar
  • 393
1 vote
1 answer
2k views

options with optional values using getopt

I have the following function and would like to look into how options with optional values can be set up using getopt. Would like to have -w taking on default values region -w -- "Text" And ...
Pietru's user avatar
  • 393

15 30 50 per page
1
3 4
5
6 7
23