title: Using getopts to store a filename as an argument
body: <p>I'm trying to learn to use the getopts() feature in bash to parse my arguments, but my program requires that in addition to my standard -a -b -c type arguments I also need to get any number of files to work on, and I can't find any information on how to make getopts recognize them instead of throwing them out as invalid arguments.  Here's an example:</p>
  
  <pre class="lang-shell prettyprint-override"><code>while getopts "a:b:c:d" flag
  do
  
      echo Doing: "$flag" $OPTIND $OPTARG
  
      if [ "$flag" = a ]; then
          first="$OPTARG"
          echo Found argument: $first
      fi
  </code></pre>
  
  <p>... and so on with other if statements.  This works great if my program just needed a command like: program -a -c , but instead I need to take in something like: program -a file.sh -c otherfile.sh.</p>
  
  <p>Can somebody show me an example of how to do something like this?</p>