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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Powershell Script 8 66
what are these modules in perl script 4 94
UNiX Script filesystem space usage Part2 54 80
IE 11 + long running scripts 3 33
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 …
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 …
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…
Windows 10 is mostly good. However the one thing that annoys me is how many clicks you have to do to dial a VPN connection. You have to go to settings from the start menu, (2 clicks), Network and Internet (1 click), Click VPN (another click) then fi…

863 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

28 Experts available now in Live!

Get 1:1 Help Now