I am trying to handle command line arguments with getopts in bash. One of the requirements is to process an arbitrary number of argument arguments (without the use of quotation marks).
1st example (only captures 1st argument)
madcap:~/projects$ ./getoptz.sh -sabc -s was triggered Argument: a
Second example (I want it to behave this way, but without specifying an argument
madcap:~/projects$ ./getoptz.sh -s "abc" -s was triggered Argument: abc
Is there any way to do this?
Here is the code that I have now:
#!/bin/bash while getopts ":s:" opt; do case $opt in s) echo "-s was triggered" >&2 args="$OPTARG" echo "Argument: $args" ;; \?) echo "Invalid option: -$OPTARG" >&2 ;; :) echo "Option -$OPTARG requires an argument." >&2 exit 1 ;; esac done
source share