[Webinar] Streamline your web hosting managementRegister Today

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 897
  • 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

[Webinar] Kill tickets & tabs using PowerShell

Are you tired of cycling through the same browser tabs everyday to close the same repetitive tickets? In this webinar JumpCloud will show how you can leverage RESTful APIs to build your own PowerShell modules to kill tickets & tabs using the PowerShell command Invoke-RestMethod.

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