$OPTARGS
holds the next word. If you want multiple values
- specify
-a value
multiple times as @scott suggests provide a multi-word string in quotes on the command line:
./script -a "foo bar baz"
then, in the script
array+=($OPTARG) # OPTARG is **unquoted**
Checking that it adds the words separately
a=(one two three) value="four five six" a+=($value) echo ${#a[@]} # prints 6