954,546 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

converting centigrade to fahrenheit unix

Hi I am trying to write a script that converts centigrade to fahrenheit and vice versa I need to use a sub-function to perform the calculations. Can anyone help me get started on this I am kinda lost and will like help learning this thank you

cyberman111
Newbie Poster
24 posts since May 2007
Reputation Points: 10
Solved Threads: 0
 

OH YEa also I have afile named cen which has the tempertures as follow
1
8
22
43
89
283
120
212
1043
100
287
now i need to convert these to fahrenheit

cyberman111
Newbie Poster
24 posts since May 2007
Reputation Points: 10
Solved Threads: 0
 

Hey There,

To convert Celsius to Fahrenheit, multiply by 1.8 and add 32 degrees.

Hope that helps you get where you're going.

eggi
Posting Pro in Training
400 posts since Oct 2007
Reputation Points: 102
Solved Threads: 47
 

nope dpesnt help me , have no clue how to sub function

cyberman111
Newbie Poster
24 posts since May 2007
Reputation Points: 10
Solved Threads: 0
 

Hey There,

If you're using bash, you can just do this (pseudocode to follow)

function MYFUNCTION {
code in here
return $answer
}


and then call it from the script with

MYFUNCTION arg1 arg2, etc


Inside the function, the arg's that you pass on the command line (arg1, arg2, etc) would be $1, $2, etc.

, Mike

eggi
Posting Pro in Training
400 posts since Oct 2007
Reputation Points: 102
Solved Threads: 47
 

I have the same damn homework, this is easy.

The subfunction is the datafile or the numbers you have to convert.

Place it in some type of while, for, or until loop. I found that the for loop is easiest way to go.

now to calculate the numbers you must place all of this in a $variable

Like : $c and $f

And use either let, expr, or bc to do the math for ya.

Here's a big hint. From the commandline type:

for i in `cat name of data file or temp file`
do
         echo $i

done


now calculate $i (or what ever $varible you used) with the formula for centigrade and fahrenheit .

Easy!

Impact4ever
Newbie Poster
14 posts since Jan 2008
Reputation Points: 10
Solved Threads: 0
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You