title: How to get program argument in a Linux shell script when also using getopts?
body: <p>So I have a script where I want to process options with <code>getopts</code> but I also want to read arguments to the program itself in the usual way. So in this example script, I want to process the options and then <code>echo</code> the argument, given like <code>./script.sh -abc theargument</code>. The problem that arises is that I don't know which shell argument is it. Argument isn't supposed to be related to the options, so you can call the script like <code>./script.sh theargument</code> as well:</p>
  
  <pre><code>#!/bin/sh
  
  while getopts "abc" opt; do
      case $opt in
          a) echo "option a" ;;
          b) echo "option b" ;;
          c) echo "option c" ;;
      esac
  done
  
  echo # what?
  </code></pre>
  
  <p>I can't just <code>shift</code> arguments with <code>$OPTIND</code> to make it <code>$1</code> because options can be given like <code>-abc</code>, <code>-a -b -c</code>, <code>-ab -c</code> etc., so number of options doesn't correspond to the number of arguments.</p>
  
  <p>Ideally I'd want to avoid bashisms</p>