Skip to main content

Questions tagged [getopts]

`getopts` is a shell built-in used to parse command line options, while `getopt` is its non-built-in counterpart.

0 votes
2 answers
81 views

More than 1 option when launch script

Is there a way to pass more than one option when running a script? My script has this case: case "$1" in b) backup_start $1 ;; h) _usage ;; *) echo 'Invalid option, -h for help' ;;...
ancoling67's user avatar
0 votes
1 answer
28 views

Trying to sort with getopts with different commands and cannot sort by price

I am trying to sort an inventory list in unix/linux below. I am successful in sorting by name and ID and able to pull up the usage menu but cannot sort by price, even with an "awk" function....
Natasha Shorrock's user avatar
0 votes
1 answer
114 views

Manipulating arguments with OPTIND, OPTARG, getopts, and shift correctly

My small POSIX shell scripts do not usually take any arguments, so this is kind of new to me... The minimal snippet would probably look like this: # default for hotkey variable on top of script is set ...
Vlastimil Burián's user avatar
0 votes
1 answer
50 views

getopt with several `--`

I have a script with this usage: myscript [options] positional-args... -- [fwd-params] Because [options] can have long, or short variants, I like using getopt. But I'm having troubles. I use getopt ...
Stewart's user avatar
  • 15.4k
-1 votes
1 answer
226 views

pass all parameters to another sourced bash script that uses getopts

I am trying to pass all parameters from one script to another. However, there is an issue when the other script is sourced; all parameters are not passing correctly. first.sh: #!/usr/bin/bash while ...
Zero's user avatar
  • 39
2 votes
1 answer
192 views

script arguments in bash

I am working on a a script that need to take two script arguments and use them as variables in the script. I couldn't get this working and unable to find out what I am doing wrong. I see the issue is ...
MO12's user avatar
  • 409
-2 votes
1 answer
816 views

Bash getopts error handling

This is an error I encountered when playing with Getopts. The following is the code snippet I have been playing simply listen to 3 options when executing a script. while getopts "vcn" opt; ...
Dettlaff404's user avatar
2 votes
1 answer
359 views

How bash getopts knows what arguments the call has

If getopts is a bash function, by my understanding, you need to pass $@ - the whole arguments to getopts to let the function know what kind of arguments you have in order to proceed, right? It seems ...
Till's user avatar
  • 193
-1 votes
1 answer
314 views

how to exit immediately with getopts option in bash script

what I tried. #!/bin/bash # set -e echo hello while getopts sr o; do case $o in s) echo "no" yell() { echo "$0: $*" >&2; } die() { yell "...
jian's user avatar
  • 597
0 votes
1 answer
1k views

What does colon (:) mean for getopts?

I am trying to parse options for my script with getopts and I decided that it would be best to read up on it in the POSIX standard, as it's usually extremely helpful. The DESCRIPTION section is fairly ...
Nicolas Dumitru's user avatar
0 votes
0 answers
56 views

Is there a tool or macro processor capable of compactly expressing BASH CLI interfaces?

I am writing scripts with the following boilerplate CLI pattern: usage(){ echo "$0 yada yada" ... echo } for arg in "$@"; do case "$arg" in '--help|-help') ...
Chris's user avatar
  • 1,055
0 votes
1 answer
194 views

Multichar options in Unix sysytems

I have a usecase wherein I need to support multiple character option. Currently I am using single character option for getopts. Multi-character option is desirable.What's the best way of doing this? I ...
Vatsal A Mehta's user avatar
-1 votes
1 answer
504 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
-2 votes
1 answer
1k views

The workings of getopts OPTIND

I want to understand how OPTIND works by getopts. If I want to skip the first few positional arguments, how should I set up OPTIND exactly ? And because OPTIND is not reset automatically, I need to ...
Vera's user avatar
  • 1
1 vote
0 answers
34 views

What the... Variable String [duplicate]

I believe I am running into a scenario where escaping quotes and utilizing variables as strings is causing some issues and after some hours of troubleshooting this isn't seeming to come to a ...
Nathan's user avatar
  • 23

15 30 50 per page
1
2 3 4 5
9