title: Batch file for parsing command line input that contains comma separated values
body: <p>I am working on a command line utility that takes set of input parameters as command.
  Those input parameters are then validated against predefined names. The utility is invoked in this manner:</p>
  
  <p><strong>runUtility.cmd</strong>    <strong>-A  -B x,y,z  -C w</strong></p>
  
  <p>Here parameters are A, B and C (one that starts with -).
  Now the validation rules are as follows:</p>
  
  <ol>
  <li><p>Parameter's name should match predefined names, so that one can not pass any invalid parameter say -UVW</p></li>
  <li><p>Parameter may or may not have a value. In above example -A has no value, while -B has x,y,z and -C has w.</p></li>
  </ol>
  
  <p>I have written this code to validate the inputs:</p>
  
  <pre><code>:validate
  
  set argument=%1
  set argumentValue=%2
  
  
  if "%argument%" == "-A" (   
      shift   
      goto validate
  )
  
  if "%argument%" == "-B" (
      if "%argumentValue%" == "" (
          echo Empty value for -B
          goto end
      )
      shift
      shift 
      goto validate       
  )
  
  if "%argument%" == "-C" (
      if "%argumentValue%" == "" (
          echo Empty value for -C
          goto end
      )
      shift
      shift  
      goto validate      
  )
  
  if %argument%" == "" (
          goto end
  )
  
  Argument %argument% is invalid
  
  :end        
  </code></pre>
  
  <p>But this does not seem to work, as -B has comma separated values, so for B when it does two shifts, in the next iteration,  y becomes %1 and z becomes %2. Since y is not a parameter, it fails with last line of code that "Argument y is invalid".
  Actually comma is taken as delimiter by SHIFT command, so x,y,z does remain a single value.</p>
  
  <p>I want x,y,z to be taken as a single value OR is there any other way to process this?
  I am bit new to batch scripting , I tried with FOR loop but there I was not able to get %1 and %2 together in every iteration.</p>