title: How to call getopts in bash multiple times
body: <p>I have a common library that I use from several scripts that parses command line options, however I also want my individual scripts to be able to process arguments as well...
  e.g.</p>
  
  <p>common.sh:</p>
  
  <pre><code>function get_options {
      echo -e "in getoptions"
      echo $OPTIND
      while getopts ":ab:" optionName; do
         [ ... processing code ... ]
      done
  }
  </code></pre>
  
  <p>a.sh</p>
  
  <pre><code>. ./common.sh
  
  function get_local_options {
      echo -e "in getoptions"
      echo $OPTIND
      while getopts ":xy:" optionName; do
         [ ... processing code ... ]
      done
  }
  
  get_local_options $*
  OPTIND=1
  get_options $*
  </code></pre>
  
  <p>The problem si that if I call a.sh with:</p>
  
  <pre><code>a.sh -x -y foo -a -b bar
  </code></pre>
  
  <p>get_options stops processing at "foo" as it stops at the first "non-option"</p>
  
  <p>Any way around this without rewriting things myself?</p>