`getopts` is a shell built-in used to parse command line options, while `getopt` is its non-built-in counterpart.
-1
votes
0answers
31 views
The logic behind implementation of getopt and programms like getopt [closed]
I would like to know the general logic behind the implementation of getopt kind of functionality, so that any script would have optional parameters or some options or parameters could be must for that ...
3
votes
5answers
64 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 ...
2
votes
2answers
59 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 ...
0
votes
1answer
86 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 ...
1
vote
0answers
137 views
Processing shell script options with awk
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 ...
6
votes
3answers
306 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
205 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
...
3
votes
2answers
613 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
133 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
267 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]. ...
6
votes
4answers
2k 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 ...
2
votes
1answer
1k 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
308 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
1k 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 ...