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

learn more… | top users | synonyms

0
votes
1answer
51 views

Using getopts to parse options after a non-option argument

I have a bash script as below in a file nepleaks_upd.sh, that I want to run as ./nepleaks_upd.sh bootstrap --branch off. Couldn't make it to take --branch , but what it works with is ./nepleaks_upd.sh ...
0
votes
0answers
47 views

how to pass asterisk as a parameter to getopts [duplicate]

I wrote a shell scripts with getopts to take arguments. But I want to pass an asterisk as an argument, for example script -a"Hello * all" -b"Another argument" if I echo the -a argument from the ...
0
votes
2answers
176 views

Alternate option field

In a script i have a list of options that needs to be entered by the user. They are -c cell name -> it must be there -n node -> it must be there -s server -> it must be there Uptill here its all ...
0
votes
2answers
65 views

How to input two arguments with getopts

Hi friends I am writing a simple bash script; My script installs ppa. The problem is I can't add two arguments. I want write a simple: ./ppa.sh -i ppa:chris-lea/node.js nodejs I tried it; but ...
1
vote
1answer
213 views

getopts - how to avoid read next $OPTARG as argument?

Just started use getopts and found one problem... For example - have a script with: while getopts "h:loav" opt; do case $opt in h) h=$OPTARG echo $h ;; But whet I run it: $ ./ftpclean.sh -h ...
3
votes
1answer
221 views

How do I fix the argument received from getopt?

I have the following commands in my script: set -- `getopt -q agvc:l:t:i: "$@"` ... while [ -n "$1" ] do -i) TIME_GAP_BOOT=$2 shift ;; ... sleep $TIME_GAP_BOOT When invoking the script ...
2
votes
2answers
331 views

shell script options pass through to sub-command

I'm writing a wrapper script for that uses getopts to set various options for mysqldump. It's working well so far. However one thing I would like to do is be able to add another option in my shell ...
4
votes
5answers
2k views

bash getopts, short options only, all require values, own validation

I'm trying to build up a shell script that accepts various options and getopts seems like a good solution as it can handle the variable ordering of the options and arguments (I think!). I'll only be ...
3
votes
2answers
315 views

Including sub-parameters in help options to execute wisely without getopt or getopts?

I am writing a script which can choose a file and print specific content. For example, san#./script.sh Expected Usage : ./script.sh --file1 --dns (Here it checks for file1, search for dns name and ...
1
vote
1answer
979 views

Multiple option arguments using getopts in bash

I am trying to process command line arguments using getopts in bash. One of the requirements is for the processing of an arbitrary number of option arguments (without the use of quotes). 1st example ...
2
votes
1answer
247 views

Simpler processing of shell script options

I'm looking for way to process shell script arguments that is cleaner and more "self documenting" than getopt/getopts. It would need to provide... Full support of long options with or without a ...
8
votes
3answers
5k views

getopt, getopts or manual parsing - what to use when I want to support both short and long options?

Currently I'm writing a Bash script which has the following requirements: it should run on a wide variety of Unix/Linux platforms it should support both short and (GNU) long options I know that ...
2
votes
2answers
1k views

How to deal with end of options — in getopts

I use getopts to parse arguments in bash scripts as while getopts ":hd:" opt; do case $opt in d ) echo "directory = $OPTARG"; mydir="$OPTARG"; shift $((OPTIND-1)); OPTIND=1 ;; h ) helptext ...
4
votes
2answers
6k views

How can I detect that no options were passed with getopts?

I have this code - #getoptDemo.sh usage() { echo "usage: <command> options:<w|l|h>" } while getopts wlh: option do case $option in (w) name='1';; ...
3
votes
2answers
240 views

how to make getopts just read the first character post `-`

I have a shell script testShell.sh which uses getopts as below: #!/bin/bash while getopts ":j:e:" option; do case "$option" in j) MYHOSTNAME=$OPTARG ;; e) SCRIPT_PATH=$OPTARG ;; ...
3
votes
2answers
562 views

Getopts option processing, Is it possible to add a non hyphenated [FILE]?

I'm using getopts for all of my scripts that require advanced option parsing, and It's worked great with dash. I'm familiar with the standard basic getopts usage, consisting of [-x] and [-x OPTION]. ...
8
votes
4answers
5k views

How do I handle switches in a shell script?

Are there some built-in tools that will recognize -x and --xxxx as switches, and not arguments, or do you have to go through all the input variables, test for dashes, and then parse the arguments ...
3
votes
1answer
3k views

How to run a specified codeblock with getopts when no options or arguments are supplied?

So I am writing a script that mixes options with arguments with options that don't. From research I have found that getopts is the best way to do this, and so far it has been simple to figure out and ...
3
votes
2answers
490 views

How to specify -? option with GNU getopt

When parsing command line arguments with GNU getopt command, how do I (if possible) do recognize -? as another option? Is there a way to escape it in the opstring?
3
votes
2answers
4k views

How to catch optioned and non optioned arguments correctly?

I want to write a shell script which will take some arguments with some options and print that arguments. Suppose the name of that script is abc.ksh. Usage of that script is - ./abc.ksh -[a ...