Improve company productivity with a Business Account.Sign Up

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 910
  • 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
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Get your problem seen by more experts

Be seen. Boost your question’s priority for more expert views and faster solutions

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