title: `else' unexpected in korn shell script
body: <p>given the code below, I get "/usr/sbin/logcheck: line 21: syntax error at line 40: `else' unexpected" as the output. I have tried using elif instead of else but that didnt work either. Any help would be much appreciated.</p>
  
  <pre><code>#!/bin/ksh
  # Set the config variables
  
  # *************************************************Configuration********************************************************
  logFileName="production.log"
  errorList="ActionController::"
  EMAIL_SUBJECT="Application ERROR"
  EMAIL_TO="viva@viva.com"
  # **********************************************************************************************************************
  
  logFilepath="data/vbmapp/vb-mapp-portal/log"
  
  # Set the Log File path
  
  if [ ! -s $logFilePath/$logFileName ]; then echo "ERROR- Log File Not Found , Please set the config properly"
  exit
  fi
  
  # Get the first 30 characters of the first line linestart=$(awk 'NR&gt;1{exit} ;1' $logFilePath/$logFileName | cut -c1-30)
  
  lineend=""
  
  # Never ending loop that will parse the Out.log file every 5 sec
  
  while true ; do
  
  # get the last line of file , till which we need to parse the log in this iteration 
  
  lineend=$(awk 'END{print}' $logFilePath/$logFileName | cut -c1-30)
  
  # if log file not found , Do nothing and wait for the next iteration 
  if [ ! -s $logFilePath/$logFileName ]; then echo "Log File Not Found .. Waiting for the next iteration ..."
  fi
  
  # error checking , in case we dont find the linestart , parse the whole file 
  grep "$linestart" $logFilePath/$logFileName if [ $? != 0 ] then
  echo "cat $logFilePath/$logFileName | egrep $errorList | /usr/sbin/sendmail -s $EMAIL_SUBJECT $EMAIL_TO"
  cat $logFilePath/$logFileName | egrep "$errorList" | /usr/sbin/sendmail -s $EMAIL_SUBJECT $EMAIL_TO
  
  else
  
  #parse the log file from linestart to lineend for errors
  
  echo 'awk "/$linestart/,/$lineend/" $logFilePath/$logFileName | egrep "$errorList" | /usr/sbin/sendmail -s $EMAIL_SUBJECT $EMAIL_TO'
  
  awk "/$linestart/,/$lineend/" $logFilePath/$logFileName | egrep "$errorList" | /usr/sbin/sendmail -s $EMAIL_SUBJECT $EMAIL_TO 
  
  #set the last line as the first line for next iteration 
  
  linestart=$lineend fi
  
  #set the last line as the first line for next iteration 
  
  linestart=$lineend
  
  sleep 5
  
  done
  </code></pre>