title: A shell script "getopts error"
body: <p>I have this code:</p>
  
  <pre><code>#!/bin/bash
  if [ $# -lt 2 ]; then
      echo "usage: $0 &lt;-lu&gt; &lt;string&gt;"
      exit 1
  fi
  while getopts "lu" OPT
  do
      case $OPT in
          u) casechange=0;;
          l) casechange=1;;
          *) echo "usage: -u&lt;upper&gt; || -l&lt;lower&gt; &lt;string&gt;";
              exit 1;;
      esac
  done
  shift $(( $optind -1 ))
  if [ $casechange -eq 0 ]; then
      tr '[A-Z]' '[a-z]' &lt;$string
  elif [ $casechange -eq 1 ]; then
      tr '[a-z]' '[A-Z]' &lt;$string
  else
      echo "fatal error"
      exit 1
  fi
  </code></pre>
  
  <p>I get two errors:</p>
  
  <ul>
  <li><code>line 15: shift -1: shift count out of range</code></li>
  <li><code>line 19: $string: ambiguous redirect</code></li>
  </ul>
  
  <p>What am I doing wrong? How do I fix this?</p>