LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 03-30-2001, 12:06 PM   #1
imnna2
LQ Newbie
 
Registered: Mar 2001
Location: Tulsa, OK
Posts: 2

Rep: Reputation: 0

I have been working about a week trying to get a script file to work, and I can't see anything but 'syntax' errors.

what i am trying to accomplish is:
I need a script that prompts user for age and weight - needs to add weight and age together; if these values combined are less than 275 it needs to 'echo' up 15 from the number ; if it is is more than 275 it needs to 'echo' down 15.


echo "Please enter your age."
read $age
echo "Please enter your weight."
read $weight

if [ $age + $weight -lt 275 ]
read $count

while [ $count -lt 275 ]

do
count = `expr $count + 1`
// this is where I am getting confused.
// what do I use to have the count stop at 15 from this total?


Thanks in advance,
imnna2

 
Old 03-30-2001, 08:17 PM   #2
crabboy
Senior Member
 
Registered: Feb 2001
Location: Atlanta, GA
Distribution: Slackware
Posts: 1,821

Rep: Reputation: 121Reputation: 121
Here is my attempt at the script. I can't say I completely understood the requirements, but I took a couple guesses.

Code:
#!/bin/sh

ECHO='/bin/echo'
LIMIT=275
INCREMENT_VALUE=1
RANGE_FROM_LIMIT=15
ACTUAL_LIMIT=0

$ECHO "Please enter you age "
read AGE

$ECHO "Please enter your weight "
read WEIGHT

AGE_WEIGHT=`expr $AGE + $WEIGHT`

if [ $AGE_WEIGHT -lt $LIMIT ]; then
   INCREMENT_VALUE=`expr $INCREMENT_VALUE '*' 1`
   ACTUAL_LIMIT=`expr $LIMIT - $RANGE_FROM_LIMIT`
   OP="-le"

elif [ $AGE_WEIGHT -gt $LIMIT ]; then
   INCREMENT_VALUE=`expr $INCREMENT_VALUE '*' -1`
   ACTUAL_LIMIT=`expr $LIMIT + $RANGE_FROM_LIMIT`
   OP="-ge"
fi

if [ $ACTUAL_LIMIT -ne 0 ]; then
   while [ $AGE_WEIGHT $OP $ACTUAL_LIMIT ]; do
      $ECHO $AGE_WEIGHT
      AGE_WEIGHT=`expr $AGE_WEIGHT + $INCREMENT_VALUE`
   done
fi

$ECHO done
exit 0
 
Old 04-02-2001, 09:44 AM   #3
imnna2
LQ Newbie
 
Registered: Mar 2001
Location: Tulsa, OK
Posts: 2

Original Poster
Rep: Reputation: 0
That's pretty close and I see what I was doing wrong, I thank you. It was supposed to increment from the total of the age & weight only 15 characters. (ie
Age was 50 and weight was 50 this would equal 100 which is less than 275; so I need it to count from 100 to 115. If the total was 300 I would need it to count from 300 down to 285.

Puzzled but learning.


 
  


Reply



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 Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Shell scripting Problems! herve2001 Linux - General 7 02-26-2005 08:57 PM
Scripting problems - I'm sure this should be easy! webamoeba Linux - Newbie 6 02-03-2004 09:58 AM
problems with scripting in expect wedgeworth Linux - Software 1 10-07-2003 03:34 PM
Scripting Problems dolvmin Linux - Software 4 08-15-2003 12:33 AM
Shell Scripting problems (newbie) yawgmoth81 Programming 11 02-24-2003 02:31 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 08:31 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration