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
832 Views
Last Modified: 2013-12-26
if [condition] ;
then
    statements;
fi;

i am getting error " unexpected fi"
0
Comment
Question by:ANISHKA1
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Enroll in May's Course of the Month

May’s Course of the Month is now available! Experts Exchange’s Premium Members and Team Accounts have access to a complimentary course each month as part of their membership—an extra way to increase training and boost professional development.

Question has a verified solution.

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

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 …
Recently, an awarded photographer, Selina De Maeyer (http://www.selinademaeyer.com/), completed a photo shoot of a beautiful event (http://www.sintjacobantwerpen.be/verslag-en-fotoreportage-van-de-sacramentsprocessie-door-antwerpen#thumbnails) in An…
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…

752 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