unexpected End of File error in if else statement

Vignesh picture Vignesh · Jun 17, 2013 · Viewed 13.4k times · Source

I keep getting unexpected End of file error while running a if else statement

#! /bin/bash
echo -e "1: Proband\n 2: mincount\n Enter an option:"
read promin
echo $promin
if ($promin == 1) then
echo -e "Enter the proband file name\n"
read proband_file
echo "$proband_file"
endif
if ($promin == 2) then
echo -e "enter the min count number\n"
read mincount
echo "$mincount mincount"
endif

I tried fi instead of elseif too. But i still get the same error. Can someone help me fix that?

Answer

Fredrik Pihl picture Fredrik Pihl · Jun 17, 2013

This is how you write an if-statement in bash:

if - then - fi

if [ conditional expression ]
then
    statement1
    statement2
fi

if - then - else - fi

If [ conditional expression ]
then
    statement1
    statement2
else
    statement3
    statement4
fi

if - then - elif - else - fi

If [ conditional expression1 ]
then
    statement1
    statement2
elif [ conditional expression2 ]
then
    statement3
    statement4
else
    statement5
fi

Example of a conditional expression:

#!/bin/bash
count=100
if [ $count -eq 100 ]
then
  echo "Count is 100"
fi