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

All Questions

Tagged with
-1 votes
1 answer
55 views

Script is not activating the options

I'm making a script to open url by terminal and when typing: #!/usr/bin/bash ## origin: https://www.vivaolinux.com.br/script/Abrir-arquivos-em-nova-aba-no-Firefox ## ### Se quizer que o novo link ...
user avatar
0 votes
1 answer
519 views

Add options with default value on shell script

I want to add some options to my custom shell script. I can show it to you since it is not top secret content :-P In my experience, there are two option types, set and unset options: set options are ...
Bruno Peixoto's user avatar
3 votes
1 answer
4k views

in bash the option "set -e" causes exit immediately, which is a problem in sourced scripts

When using bash in a terminal often scripts have to be run sourced. In such cases terminating the script must be done by "return", but not by "exit" in order to not kill the basic ...
Anton Wessel's user avatar
0 votes
1 answer
439 views

getopt and case function not executing

I encountered such a problem when passing a parameter to a script, the function corresponding to the case menu is not executed. The script accepts parameters as input and performs the appropriate ...
Maverick's user avatar
1 vote
1 answer
9k views

What does the "+x" option in "bash +x script.sh" mean?

I know what bash -x does, but what does bash +x do? Googling found no results and the manual also says nothing about it.
user1206899's user avatar
1 vote
1 answer
1k views

Invoke a program in a Bash script with command line parameters stored in a variable

Is it possible to invoke some program in a Bash script with complete command line parameters (both the key and the value) stored in variables? I use the following scanimage call in a script: scanimage ...
Tobias Leupold's user avatar
1 vote
1 answer
2k views

How to get option value $OPTARG correctly?

I would like to get an option value when launching a shcell. I wrote: optstring=hcnxl: V=0 while getopts $optstring opt; do case $opt in h) V=1 ;; c) V=2 ;; n) V=3 ;; x) V=4 ;; ...
Gigiux's user avatar
  • 527
-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
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
-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
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

15 30 50 per page