title: Bash: syntax error near unexpected token `else'
body: <p>I have the following code that checks whether either of two input args are supplied, and depending on their existance runs a certain piece of code. I'm running into syntax errors in my if statements however, because I'm getting an unexpected token `else' error</p>
  
  <pre><code>if [ -z "${4}" ] || [ -z "${5}" ]
  then
      echo "Missing index argument(s). Defaulting to entire file."
      cat ${devicesFile} | cut -d "," -f 4 | tr [:upper:] [:lower:] | awk '{print substr($1,1,8)"-"substr($1,9,4)"-"substr($1,13,4)"-"substr($1,17,4)"-"substr($1,21,12)}' | while read deviceGuid
  else
      i1=${4}
      i2=${5}
      head -n ${i1} ${devicesFile} | tail -n ${i2} | cut -d "," -f 4 | tr [:upper:] [:lower:] | awk '{print substr($1,1,8)"-"substr($1,9,4)"-"substr($1,13,4)"-"substr($1,17,4)"-"substr($1,21,12)}' | while read deviceGuid
  fi
  </code></pre>
  
  <p>Is it an issue with my or condition.? That's the only thing I can really think of. Any help would be greatly appreciated.</p>
  
  <p>//Here's what I had before I tried to add the index parameters, so what HVD said about the broken while makes sense..</p>
  
  <pre><code>cat ${devicesFile}  | cut -d "," -f 4 | tr [:upper:] [:lower:] | awk '{print substr($1,1,8)"-"substr($1,9,4)"-"substr($1,13,4)"-"substr($1,17,4)"-"substr($1,21,12)}' | while read deviceGuid
  do
      # now=`date +"%Y%m%d %H%M%S"`
      currentTime=`date +"%H%M%S"`
      currentHour=`date +"%H"`
      currentDate=`date +"%Y%m%d"`
      # create parent directory
      mkdir -p ${crashlogFolder}/${currentDate}/${currentHour}/${crashCode}/
      # create crash log for device
      touch ${crashlogFolder}/${currentDate}/${currentHour}/${crashCode}/${currentTime}_${deviceGuid}.log
  done
  </code></pre>