943,722 Members | Top Members by Rank

Ad:
Apr 22nd, 2008
0

converting centigrade to fahrenheit unix

Expand Post »
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
Reputation Points: 10
Solved Threads: 0
Newbie Poster
cyberman111 is offline Offline
24 posts
since May 2007
Apr 22nd, 2008
0

Re: converting centigrade to fahrenheit unix

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
Reputation Points: 10
Solved Threads: 0
Newbie Poster
cyberman111 is offline Offline
24 posts
since May 2007
Apr 22nd, 2008
0

Re: converting centigrade to fahrenheit unix

Hey There,

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

Hope that helps you get where you're going.
Reputation Points: 102
Solved Threads: 47
Posting Whiz
eggi is offline Offline
399 posts
since Oct 2007
Apr 22nd, 2008
0

Re: converting centigrade to fahrenheit unix

nope dpesnt help me , have no clue how to sub function
Reputation Points: 10
Solved Threads: 0
Newbie Poster
cyberman111 is offline Offline
24 posts
since May 2007
Apr 22nd, 2008
0

Re: converting centigrade to fahrenheit unix

Hey There,

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

Shell Scripting Syntax (Toggle Plain Text)
  1. function MYFUNCTION {
  2. code in here
  3. return $answer
  4. }

and then call it from the script with

Shell Scripting Syntax (Toggle Plain Text)
  1. 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
Reputation Points: 102
Solved Threads: 47
Posting Whiz
eggi is offline Offline
399 posts
since Oct 2007
Apr 25th, 2008
0

Re: converting centigrade to fahrenheit unix

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:

Shell Scripting Syntax (Toggle Plain Text)
  1. for i in `cat name of data file or temp file`
  2. do
  3. echo $i
  4.  
  5. done

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

Easy!
Reputation Points: 10
Solved Threads: 0
Newbie Poster
Impact4ever is offline Offline
14 posts
since Jan 2008

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in Shell Scripting Forum Timeline: Help in creating a user in Multiple servers
Next Thread in Shell Scripting Forum Timeline: can you create a script in windows





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC