Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 882
  • Last Modified:

If i have to use if condition in korn shell script...do i need to give semicolon after if like

if [condition] ;
then
    statements;
fi;

i am getting error " unexpected fi"
0
ANISHKA1
Asked:
ANISHKA1
1 Solution
 
omarfaridCommented:
you don't have to, e.g.

if [ -f /etc/hosts ]
then
      echo yes
else
     echo no
fi
0
 
chiragypatilCommented:
remove the semicolon .
use it only when "then" is on the same line, as in

also note the spaces before and after square brackets.

if [ condition ];then
dothething
else
dosomething
fi

Open in new window

0
 
sarav84Commented:
You should give at least one space after open bracket and before close bracket.

Look at the above example given by chiragypatil.
0
 
ANISHKA1Author Commented:
I have resolved it!
0

Featured Post

Ask an Anonymous Question!

Don't feel intimidated by what you don't know. Ask your question anonymously. It's easy! Learn more and upgrade.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now