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
804 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
Comment Utility
you don't have to, e.g.

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

Expert Comment

by:chiragypatil
Comment Utility
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
Comment Utility
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
Comment Utility
I have resolved it!
0

Featured Post

What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Suggested Solutions

This Windows batch file is useful for organizing image files from a digital camera or other source, but can have many other uses.  It simply renames the file(s) to match their create date.  For example, if you took a picture today at 1:40pm and the …
Background Still having to process all these year-end "csv" files received from all these sources (including Government entities), sometimes we have the need to examine the contents due to data error, etc... As a "Unix" shop, our only readily …
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…
This video explains how to create simple products associated to Magento configurable product and offers fast way of their generation with Store Manager for Magento tool.

772 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

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now