title: Retrieving multiple arguments for a single option using getopts in Bash
body: <p>I need help with <code>getopts</code>.</p>
  
  <p>I created a Bash script which looks like this when run:</p>
  
  <p>$ foo.sh -i env -d directory -s subdirectory -f file</p>
  
  <p>It works correctly when handling one argument from each flag.  But when I invoke several arguments from each flag I am not sure how to pull the multiple variable information out of the variables in <code>getopts</code>.</p>
  
  <pre><code>while getopts ":i:d:s:f:" opt
     do
       case $opt in
          i ) initial=$OPTARG;;
          d ) dir=$OPTARG;;
          s ) sub=$OPTARG;;
          f ) files=$OPTARG;;
  
       esac
  done
  </code></pre>
  
  <p>After grabbing the options I then want to build directory structures from the variables</p>
  
  <pre><code>foo.sh -i test -d directory -s subdirectory -s subdirectory2 -f file1 file2 file3
  </code></pre>
  
  <p>Then the directory structure would be</p>
  
  <pre><code>/test/directory/subdirectory/file1
  /test/directory/subdirectory/file2
  /test/directory/subdirectory/file3
  /test/directory/subdirectory2/file1
  /test/directory/subdirectory2/file2
  /test/directory/subdirectory2/file3
  </code></pre>
  
  <p>Any ideas?</p>