title: Better way of parsing the input
body: <p>My shell script takes in a set of input variables some are optional. The input should follow the following signature. </p>
  
  <p>myscript.sh var1 var2 [-x var3] [-y var4]`. </p>
  
  <p>The -x and -y are <strong>optional</strong> inputs and these options can occur at any location (between var1 &amp; var 2 or at the start) but var3 will always preceed var4. Also var1 will preceed var 2.</p>
  
  <p>The script I have does a lot of if else checks to cover all the probabilities. 
  Something like this  </p>
  
  <pre><code>if [ $1 == "-x" ]; then
  ## Then check if $3 == "-y" 
  ## Assign values to VAR1 , VAR2, VAR3, VAR4 
  ## else check for other possibilities
  fi
  </code></pre>
  
  <p>I was wondering if there was a better way of doing this and assigning the values to variables? </p>