The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

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
ksh scripting help praveenbvarrier Shell Programming and Scripting 1 04-15-2008 10:19 AM
sql scripting help sam786 Shell Programming and Scripting 3 12-10-2007 12:31 PM
difference between AIX shell scripting and Unix shell scripting. haroonec Shell Programming and Scripting 2 04-12-2006 08:12 AM
scripting guru's pls help me with scripting on AIX thatiprashant Shell Programming and Scripting 1 01-20-2006 07:58 PM
Scripting? woofie What's on Your Mind? 1 03-09-2005 07:03 AM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 05-14-2008
tiney83 tiney83 is offline
Registered User
  
 

Join Date: May 2008
Posts: 3
Scripting help

Hi,
I have an assignment for my Unix class to write a program asking a user to enter a number. the user then chooses an option from a menu of whether they want to count down to zero from the number they entered, or count up from zero to the number. The error i keep getting is binary operator expected for lines 9 and 14 , than when i change that it says unary operator expected. Also I want to know if I coded this whole thing corretly. any ideas?

Code:
echo "Enter a number"
read $number
echo "What do you want to do to this number?"
echo "Enter d, to count down to zero"
echo "Enter u, to count  up from zero"
read choice
case $choice in
d) while [ "$number" \>= "0" ]
do
echo $number
$number = `expr $number - 1`
done;;
u) while [ "0" \<= "$number" ]
do
echo $number
$number = `expr $number + 1`
done;;
esac
echo "bye"
~
  #2 (permalink)  
Old 05-14-2008
Smiling Dragon's Avatar
Smiling Dragon Smiling Dragon is offline Forum Advisor  
Disorganised User
  
 

Join Date: Nov 2007
Location: New Zealand
Posts: 921
It looks like you might be hitting problems with some of your variables not getting set correctly. To debug, try adding an echo line for each variable just before you go to use it to check everything is as it should be.

Also, check that you are using the right comparison operator, I'm pretty sure = works for numbers, not quoted strings.

Rules of unix.com prevent very explicit help on classwork but I'm sure we can help you on useful debugging steps.
  #3 (permalink)  
Old 05-14-2008
tiney83 tiney83 is offline
Registered User
  
 

Join Date: May 2008
Posts: 3
Hi, Thank you Smiling Dragon. i fixed the problems with not having the dollar sign in front of the choice variable. however, now i can run the script and I get no errors, but nothing outputs except the "bye" at the end. I know you cant give me the answer, but would you know how to point in the right direction?
  #4 (permalink)  
Old 05-14-2008
rubin's Avatar
rubin rubin is offline Forum Advisor  
Registered User
  
 

Join Date: Nov 2007
Posts: 321
As Smiling Dragon mentioned it's against the forum's rules posting homework..., but at least you have put some effort:

Code:
echo "Enter a number"
read number
echo "What do you want to do to this number?"
echo "Enter d, to count down to zero"
echo "Enter u, to count  up from zero"
read choice
case $choice in
d) while [ "$number" -ge 0 ]
do
echo $number
number=`expr $number - 1`      # no spaces here before/after = sign
done;;
u) while [ 0 -le "$number" ]
do
echo $number
number=`expr $number + 1`
done;;
esac
echo "bye"
~

Last edited by rubin; 05-14-2008 at 07:59 PM.. Reason: removed extra $$
  #5 (permalink)  
Old 05-14-2008
tiney83 tiney83 is offline
Registered User
  
 

Join Date: May 2008
Posts: 3
Thank you both SO much for your help!!!
Sponsored Links
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 04:03 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language translation by Google.
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