title: An example of how to use getopts in bash
body: <p>I want to call <code>myscript</code> file in this way:</p>
  
  <pre><code>$ ./myscript -s 45 -p any_string
  </code></pre>
  
  <p>or</p>
  
  <pre><code>$ ./myscript -h  #should display help
  $ ./myscript     #should display help
  </code></pre>
  
  <p>My requirements are:</p>
  
  <ul>
  <li><code>getopt</code> here to get the input arguments</li>
  <li>check that <code>-s</code> exists, if not return an error</li>
  <li>check that the value after the <code>-s</code> is 45 or 90</li>
  <li>check that the <code>-p</code> exists and there is an input string after</li>
  <li>if the user enters <code>./myscript -h</code> or just <code>./myscript</code> then display help</li>
  </ul>
  
  <p>I tried so far this code:</p>
  
  <pre><code>#!/bin/bash
  while getopts "h:s:" arg; do
    case $arg in
      h)
        echo "usage" 
        ;;
      s)
        strength=$OPTARG
        echo $strength
        ;;
    esac
  done
  </code></pre>
  
  <p>But with that code I get errors.  How to do it with Bash and <code>getopt</code>?</p>