Bash scripting help  | |
April 20th, 2004, 03:55 AM
|
#1 (permalink)
| | Ultimate Member
Join Date: Oct 2001 Location: Gold Coast,Australia
Posts: 2,476
|
Hi all,
We got this mini test like 2 weeks ago and I have no clue how to do it.
Here what we wew asked to do:
Program will prompt user for correct information, then calculate charge from the following table. Code: Weight Destination Handling Code Surcharge
10- 100 Brisbane S 10
101-200 Brisbane S 15
10- 100 Brisbane E 20
101-200 Brisbane E 35
10- 100 Sydney S 12
101-200 Sydney S 19
10- 100 Sydney E 28
101-200 Sydney E 45
The program will tell the user the following information in this format:
Package of 10 grams
Destination Sydney
Surcharge 12.00
Handling S
-----
Im not a complete newbi at scripting, im just hopeless at figuring out these kinds of problems, so a point in the direction of where I should start would be great. This is not a test for grading so dont worry about helping to much..
Thanks.
Last edited by [Neo770] : April 21st, 2004 at 05:26 AM.
|
| |
April 20th, 2004, 11:52 AM
|
#2 (permalink)
| | dword to your moms
Join Date: Oct 2001 Location: ~/
Posts: 3,195
|
Well, basically just use echo to send out information, read to get info.
That info will come in as the $REPLY variable, so that you can set up conditionals to calculate your charge.
eg.
#!/bin/bash
echo "Enter some random number sucka"
read
echo "Here it is again"
echo $REPLY |
| |
April 20th, 2004, 06:14 PM
|
#3 (permalink)
| | Ultimate Member
Join Date: Oct 2001 Location: Gold Coast,Australia
Posts: 2,476
|
Thanks, but the bit that I need help with is the process of calculating the charge. 
__________________
(\(\
(o'.')
(,,)('')('')
|
| |
April 21st, 2004, 12:09 AM
|
#4 (permalink)
| | dword to your moms
Join Date: Oct 2001 Location: ~/
Posts: 3,195
|
Ah, sorry 
Well, the easiest way to do it is to construct nested conditionals.
I dont know how you will prompt for the information, but an easy way to do it would be as so Code: if (type)
if (dest)
if (length)
else //other type
if (dest)
if (length)
with the appropriate elseif statements.
I don't know if I understand where your problem lies here  Feel free to be more specific, ie the logic, actual calculation, etc and this could be made much simpler  |
| |
April 21st, 2004, 05:29 AM
|
#5 (permalink)
| | Ultimate Member
Join Date: Oct 2001 Location: Gold Coast,Australia
Posts: 2,476
|
Ok the logic is where I always have trouble in programming. This is a network engineering course not a programming course.
The teacher started to work through the solution in class today.
It went something like:
if weight is greater then 10 and less then 100 then process low weight
else process high weight if between 100 and 200
---------
That’s how the if statement started out
Basically say that the weight was 50 going to brisbane with Standard handling then the program would say it equals 10
He said it could also be done with the case statement but as to not confuse us he is only showing us the if/then way.
That’s as far as we got today and next Linux scripting class is not till next week unfortunately.
Thanks for the help so far  |
| |
April 21st, 2004, 11:12 PM
|
#6 (permalink)
| | Misanthropic
Join Date: Oct 2001 Location: Bay Area, California
Posts: 19,304
| Quote: Originally posted by krohnjw echo "Enter some random number sucka" | Yes, the best line of code ever... 
Where was Eddy on this one? I know he loves bash scripting... |
| | | Thread Tools | Search this Thread | | | | |
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | | | | Most Active Discussions | | | | | Recent Discussions  | | | | | |