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

All Questions

Tagged with
0 votes
0 answers
46 views

How to gracefully handle differences in command options between different versions?

Inspired by What is the difference between “base64 -b0” in macOS versions prior to macOS 13 (Ventura) and “base64 -i” in macOS 13 (Ventura)? Are there common ways to avoid the script breaking on a ...
typo's user avatar
  • 229
8 votes
1 answer
894 views

Looking for a more permissive alternative to GNU getopt for wrapper script

I often find myself writing shell functions or shell scripts that are meant to be wrappers around other commands. It is also frequent that I want such a wrapper to support a few flags/options. The ...
kjo's user avatar
  • 15.7k
-1 votes
1 answer
329 views

How to check for passed options using getopts in a POSIX shell? (Report, count, and discard.)

How to check for passed options using getopts (man page) in a POSIX shell? (Report, count, and discard.) My idea is this: Many of my scripts take no options (not even -h for help, I am transitioning ...
Vlastimil Burián's user avatar
0 votes
2 answers
356 views

Error parsing arguments for options in script Unexpected option in Shell Script

I'm trying to parsearg arguments to pass options to the script. but it is showing the following errors Unexpected option: -u in addition to looping below: $ gitpratico -u "<usuario_github>&...
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
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
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
731 views

Bash function with dry-run and exec options [closed]

Am writing a bash function to run rsync, with possibility of using --dry-run option and --exec option. Need some criticism improvements and additional checks. Might not make much sense for the user ...
Pietru's user avatar
  • 393
0 votes
1 answer
1k views

grep flag to NOT ignore case

I have a simple script to search patterns in my code sources, named prgrep #!/usr/bin/bash grep -irnI --exclude-dir={.git,obj} --exclude=tags --color=auto "$@" (The fact that it is a script ...
Hobber's user avatar
  • 398
1 vote
1 answer
1k views

If no argument is given to mandatory option, zparseopts takes next option as the argument

I am using zsh 5.4.2. The function that is causing issue is: function zp () { zparseopts -E -watch:=o_watch -show=o_show echo "show : $o_show" echo "watch ...
Ahmad Ismail's user avatar
  • 2,738
1 vote
1 answer
1k views

How do I make an option (not argument of the option) mandatory in zparseopts?

In the example bellow: function zp () { zparseopts -E -walk:=o_walk echo "walk: $o_walk" } I get the following output: $ zp --walk "Walking" walk : --walk ...
Ahmad Ismail's user avatar
  • 2,738
1 vote
1 answer
2k views

How do I pass long-style command line options to a bash script using getopt?

I have this script that I have cobbled together from bits of lore I've gleaned from googling: #!/usr/bin/env bash usage() { declare -r script_name=$(basename "$0") echo """ Usage: "${...
braveterry's user avatar
-1 votes
1 answer
62 views

Why does adding -prune to my sync script cause rsync to do a DRY-RUN?

I'm testing a script to do a by-directional sync of two directories intelligently using rsync. Since I'm testing many of the rsync options are not applicable to the testing environment including the ...
Jesse the Wind Wanderer's user avatar

15 30 50 per page