title: Parsing command line arguments in a function
body: <p>My code:</p>
  
  <pre><code>#options() {
  while getopts s:v:h opt; do
    case ${opt} in
      s)
        echo -s passed with ${OPTARG}
        ;;
      v)
        echo -v passed with ${OPTARG}
        ;;
      h)
        usage
        exit
        ;;
      *)
        usage
        exit
        ;;
    esac
  done
  #}
  #options
  </code></pre>
  
  <p>If I call it in a script everything works as expected. But as soon as I remove the hashes and make a function of the code I never get into the case marks.</p>
  
  <p>Can someone explain this behavior?</p>
  
  <p>EDIT:</p>
  
  <p>The following is my latest insight.</p>
  
  <p>There are 3 possible scopes for variables inside shell scripts:</p>
  
  <ol>
  <li>local</li>
  <li>global</li>
  <li>"in-main-visible-only" or whatever the exact name is for that scope.</li>
  </ol>