mercredi 27 avril 2016

Getting "syntax error near unexpected token `else’" in shell script

I’m using bash shell on Amazon Linux. When I run the below block of code

if [ $rc -eq 0 ] then
  passed=`tr ' ' '\n' < $TFILE | grep -c PASSED`
  error=`tr ' ' '\n' < $TFILE | grep -c ERROR`
  warning=`tr ' ' '\n' < $TFILE | grep -c WARNING`
  subject="Automated Results - $passed passed, $error errors, $warning warnings."
else
  subject="Failed to run any tests."
fi

I get the error, “syntax error near unexpected token `else’”. What do I need to do to write this if-then-else block correctly?

Aucun commentaire:

Enregistrer un commentaire