Solved

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

Posted on 2009-04-07
5
819 Views
Last Modified: 2013-12-26
if [condition] ;
then
    statements;
fi;

i am getting error " unexpected fi"
0
Comment
Question by:ANISHKA1
5 Comments
 
LVL 40

Accepted Solution

by:
omarfarid earned 500 total points
ID: 24090416
you don't have to, e.g.

if [ -f /etc/hosts ]
then
      echo yes
else
     echo no
fi
0
 

Expert Comment

by:chiragypatil
ID: 24105585
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
 

Expert Comment

by:sarav84
ID: 24681015
You should give at least one space after open bracket and before close bracket.

Look at the above example given by chiragypatil.
0
 

Author Closing Comment

by:ANISHKA1
ID: 31567588
I have resolved it!
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

The following is a collection of cases for strange behaviour when using advanced techniques in DOS batch files. You should have some basic experience in batch "programming", as I'm assuming some knowledge and not further explain the basics. For some…
Active Directory replication delay is the cause to many problems.  Here is a super easy script to force Active Directory replication to all sites with by using an elevated PowerShell command prompt, and a tool to verify your changes.
Learn several ways to interact with files and get file information from the bash shell. ls lists the contents of a directory: Using the -a flag displays hidden files: Using the -l flag formats the output in a long list: The file command gives us mor…
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…

860 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question