Answer given here doesn't here any of my questions: bash getopts with multiple and mandatory options
I am new to shell script and trying to write a shell script with getopts
meanwhile I couldn't find answers to the below questions. Can somebody please help here?
This is the script I've started writing:
#!/bin/bash while getopts c:t:x: option ; do case $option in c) java -jar $file --fail-if-no-tests --include-classname "$OPTARG" --scan-class-path $file --include-tag regression ;; t) java -jar $file --fail-if-no-tests --include-classname '.*' --scan-class-path $file --include-tag "$OPTARG" ;; c | t) java -jar $file --fail-if-no-tests --include-classname "$OPTARG" --scan-class-path $file --include-tag "$OPTARG" ;; *) usage esac done
- How do I pass multiple flags?
For example runner.sh -c classname -t tagname
I Tried usingct
,c|t
in thegetopts
but did not work. - How do I pass multiple arguments for one flag?
For example runner.sh -g arg1 arg2
- Is there a way if I don't provide any flag
it will run by default statement. I tried to achieve this using
*
but there is one issue with this approach. In case the wrong flag is provided it will always run default statement.