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
814 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

Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

Question has a verified solution.

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

How to remove superseded packages in windows w60 or w61 installation media (.wim) or online system to prevent unnecessary space. w60 means Windows Vista or Windows Server 2008. w61 means Windows 7 or Windows Server 2008 R2. There are various …
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…
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…

776 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