title: Bug in parsing args with getopts in bash
body: <p>I was trying to modify the <a href="https://github.com/vigneshwaranr/bd" rel="noreferrer">bd</a> script to use <code>getopts</code>. I am a newbie at bash scripting</p>
  
  <p>my script is </p>
  
  <pre><code>while getopts ":hvis:d:" opt
  do
  ...
  done
  
  ...
  
  echo $somedirpath
  cd "$somedirpath"    
  </code></pre>
  
  <p>this runs fine when doing</p>
  
  <pre><code>$ ./bd -v -i -s search
  </code></pre>
  
  <p>or</p>
  
  <pre><code>$ ./bd -is search -d dir
  </code></pre>
  
  <p>But when running it like this </p>
  
  <pre><code>$ . ./bd -s search
  </code></pre>
  
  <p><code>getopts</code> doesn't read the arguments at all. And all the variables I set in the <code>while</code> loop according to the arguments are all not set, so the script no longer works. Please help!</p>