The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
Google UNIX.COM


Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
IF THEN ELIF question in BOURNE SHELL arun_st UNIX for Dummies Questions & Answers 4 04-20-2007 09:41 AM
Bourne-again shell mrsamer UNIX for Dummies Questions & Answers 3 09-29-2006 11:42 PM
bourne shell not working gillbates Shell Programming and Scripting 6 06-17-2004 01:22 PM
bourne shell timing question gillbates UNIX for Dummies Questions & Answers 7 02-01-2004 01:44 PM
bourne shell script psrinivas Shell Programming and Scripting 2 12-06-2001 12:38 PM

Reply
 
Submit Tools LinkBack Thread Tools Search this Thread Display Modes
  #1  
Old 03-09-2008
Registered User
 

Join Date: Mar 2008
Posts: 2
Bourne Shell: if elsif question

Hi All,
Must be something obvious I am missing, but the simple script below doesn't work.

#!/bin/sh
x=4
if [ "$x" -eq "4" ]
then
echo "x is $x"
elsif [ "$x" -gt "4" ]
then
echo "x is greater than 4"
else
echo "x is less than 4"
fi

When I run this script, I get the error message:
7: Syntax error "then" unexpected (expecting "fi")

Please Help.

Thanks in Advance.
Reply With Quote
Forum Sponsor
  #2  
Old 03-09-2008
Registered User
 

Join Date: Mar 2008
Posts: 13
ok, for one you dont need all those quotes in the if statement. and i do believe your elsif is supposed to be spelled elif.. maybe that will help?
Reply With Quote
  #3  
Old 03-09-2008
Moderator
 

Join Date: Dec 2003
Location: /dev/fl
Posts: 1,059
This should work for you

Code:
#!/bin/sh
x=4
if [ "$x" -eq "4" ]
then
   echo "x is $x"
elif [ "$x" -gt "4" ]
then
   echo "x is greater than 4"
else
   echo "x is less than 4"
fi
Reply With Quote
  #4  
Old 03-09-2008
Registered User
 

Join Date: Mar 2008
Posts: 2
Thanks. That was it. Strange that the website from where I am learning shell scripting has it elsif everywhere..hmm.
Reply With Quote
Google The UNIX and Linux Forums
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes




All times are GMT -7. The time now is 04:03 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited.
The UNIX and Linux Forums Content Copyright ©1993-2008. All Rights Reserved.Ad Management by RedTyger Visit The Complex Event Processing Blog

Content Relevant URLs by vBSEO 3.2.0