The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > UNIX for Dummies Questions & Answers
Google UNIX.COM


UNIX for Dummies Questions & Answers If you're not sure where to post a UNIX or Linux question, post it here. All UNIX and Linux newbies welcome !!

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
have a problem with if elif loop .. plz help me with the script Syms UNIX for Dummies Questions & Answers 4 10-31-2007 11:59 PM
IF THEN ELIF question in BOURNE SHELL arun_st UNIX for Dummies Questions & Answers 4 04-20-2007 09:41 AM
If..elif..else...fi Rock Shell Programming and Scripting 2 02-08-2007 03:32 AM
elif not expected pv0428 Shell Programming and Scripting 9 07-28-2005 01:38 AM
if...elif...fi condition in Unix abidmalik UNIX for Dummies Questions & Answers 9 09-05-2002 05:35 AM

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

Join Date: May 2008
Posts: 5
Help with ELIF statement

I am receiving an elif error on line 13 and I can not figure out the reasoning behind it. I have added the then statement that I was initially missing. Any help would be great.


#The purpose of this script is for the end user to be able to enter a positive number
#User enters a number
NUM=$1
#If user enters more than one it will return this statement
if [ $# -ne1 1 ] then
echo "Only enter one number!"
exit
#For if the user enters a negative number
elif [ $NUM -le 0 ] then
echo "Enter a positive number!"
fi
#Executionary if statement
while [ "$NUM" -gt 0 ]
do
printf $NUM
if[ $NUM -gt 1 ] then
printf ","
fi
NUM=$((NUM - 1))
done


Thanks
Reply With Quote
Forum Sponsor
  #2  
Old 05-18-2008
era era is offline
Herder of Useless Cats
 

Join Date: Mar 2008
Location: /there/is/only/bin/sh
Posts: 3,650
You are missing a semicolon before an earlier then. Also -ne is misspelled.

The syntax of the if statement is

Code:
if some command or other; then
   action
else
   otheraction
fi
Because "some command or other" can be as long or short as necessary, you really do need a semicolon or a newline before the "then".
Reply With Quote
  #3  
Old 05-18-2008
Registered User
 

Join Date: May 2008
Posts: 5
It still shows me as having an issue with the done portion of my while loop at the end, I tried moving the done above and below the last statement but it wont work.
Reply With Quote
  #4  
Old 05-18-2008
era era is offline
Herder of Useless Cats
 

Join Date: Mar 2008
Location: /there/is/only/bin/sh
Posts: 3,650
Did you fix the if inside the while also?
Reply With Quote
  #5  
Old 05-18-2008
Registered User
 

Join Date: May 2008
Posts: 5
Nope...that fixed it though.

Thanks.
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 08:07 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