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 11-01-2007 02:59 AM
IF THEN ELIF question in BOURNE SHELL arun_st UNIX for Dummies Questions & Answers 4 04-20-2007 01:41 PM
If..elif..else...fi Rock Shell Programming and Scripting 2 02-08-2007 06:32 AM
elif not expected pv0428 Shell Programming and Scripting 9 07-28-2005 05:38 AM
if...elif...fi condition in Unix abidmalik UNIX for Dummies Questions & Answers 9 09-05-2002 09:35 AM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Bulgarian Greek Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 05-18-2008
Brewer27 Brewer27 is offline
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
  #2 (permalink)  
Old 05-18-2008
era era is offline Forum Advisor  
Herder of Useless Cats (On Sabbatical)
  
 

Join Date: Mar 2008
Location: /there/is/only/bin/sh
Posts: 3,652
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".
  #3 (permalink)  
Old 05-18-2008
Brewer27 Brewer27 is offline
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.
  #4 (permalink)  
Old 05-18-2008
era era is offline Forum Advisor  
Herder of Useless Cats (On Sabbatical)
  
 

Join Date: Mar 2008
Location: /there/is/only/bin/sh
Posts: 3,652
Did you fix the if inside the while also?
  #5 (permalink)  
Old 05-18-2008
Brewer27 Brewer27 is offline
Registered User
  
 

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

Thanks.
Closed Thread

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 03:18 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0