home hardware prices news articles forums photos user reviews
Go Back   Tech Support Forums - TechIMO.com > PC Hardware and Tech > Linux and Unix
Ask a Tech Support Question (free)!

Bash scripting help

Reply
Get bargains at  »  Dealighted.com
 
Thread Tools Search this Thread
Currently Active Users: 1584
Discussions: 204,479, Posts: 2,418,978, Members: 249,897
Old April 20th, 2004, 03:55 AM   Digg it!   #1 (permalink)
Ultimate Member
 
[Neo770]'s Avatar
 
Join Date: Oct 2001
Location: Gold Coast,Australia
Posts: 2,476
Send a message via MSN to [Neo770]
Bash scripting help

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.
[Neo770] is offline   Reply With Quote
Old April 20th, 2004, 11:52 AM     #2 (permalink)
dword to your moms
 
krohnjw's Avatar
 
Join Date: Oct 2001
Location: ~/
Posts: 3,195
Send a message via AIM to krohnjw
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
krohnjw is offline   Reply With Quote
Old April 20th, 2004, 06:14 PM     #3 (permalink)
Ultimate Member
 
[Neo770]'s Avatar
 
Join Date: Oct 2001
Location: Gold Coast,Australia
Posts: 2,476
Send a message via MSN to [Neo770]
Thanks, but the bit that I need help with is the process of calculating the charge.
__________________
(\(\
(o'.')
(,,)('')('')
[Neo770] is offline   Reply With Quote
Old April 21st, 2004, 12:09 AM     #4 (permalink)
dword to your moms
 
krohnjw's Avatar
 
Join Date: Oct 2001
Location: ~/
Posts: 3,195
Send a message via AIM to krohnjw
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
krohnjw is offline   Reply With Quote
Old April 21st, 2004, 05:29 AM     #5 (permalink)
Ultimate Member
 
[Neo770]'s Avatar
 
Join Date: Oct 2001
Location: Gold Coast,Australia
Posts: 2,476
Send a message via MSN to [Neo770]
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
[Neo770] is offline   Reply With Quote
Old April 21st, 2004, 11:12 PM     #6 (permalink)
Misanthropic
 
Join Date: Oct 2001
Location: Bay Area, California
Posts: 19,304
Blog Entries: 10
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...
Mike is offline   Reply With Quote
Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Most Active Discussions
would this build be enough for WOW? (11)
Is It Just Me? (1496)
Motherboard the culprit? (5)
Fighting Utility Companies (10)
Recent Problem (7)
I need help Guess what happened to .. (5)
Can't Rename Files (11)
Need some suggestions on building a.. (21)
[ F@H Chat] 03/07/10 New Month New.. (84)
My PC shutsdown after 30 minutes of.. (5)
Compaq presario V5000 LAN Driver (8)
Drive 0 not found: Serial ATA, Sata.. (6)
Need LG W2343T monitor driver (6)
Processor speeds? (19)
Recent Discussions
Recent Problem (7)
Suggestions? (3)
3D Pinball for Windows High Score (122)
Motherboard the culprit? (5)
mac noob in need of help please (0)
Hard drive full = slower computer? Is.. (4)
Processor speeds? (19)
would this build be enough for WOW? (11)
Clean up safe to delete? (4)
Where to buy 3Rsystem Iceage 120 Boss.. (3)
Need some suggestions on building a g.. (21)
2.6.12, Linux kernel (3)
I need help Guess what happened to my.. (5)
[ F@H Chat] 03/07/10 New Month New T.. (84)
Can 2 cards run off 1 pcie 16 slot (2)
Drive 0 not found: Serial ATA, Sata-0 (6)
Microsoft removes hardware virtualiza.. (0)
Screen Flickers @ Bios, Waves at Desk.. (0)
Writing lead-out (6)
Broken PaperPort 10 Link (5)
Windows XP Pro Error log (4)
Lost Password - Win7 (8)
YOUR BEST TRICK OR TIP FOR YOUR COMPU.. (19)
Help (1)
Logitech web cam (1)


All times are GMT -4. The time now is 07:46 PM.
TechIMO Copyright 2009 All Enthusiast, Inc.



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28