1.

Solve : Need help with a Script?

Answer»

I am trying to run a script called f2c with the following formula:

C = (F- 32) 5/9. This is what I have so far:

#! /bin/sh -f
#f2c
TEMP='expr ( $1 - 32\) \* 5/9'
echo "The Celsius temp is: ${TEMP}"

Does this LOOK correct to you. When I type f2c in the COMMAND prompt I get:

The Celsius temp is: ${TEMP}

Thanks in advance for your HELP.

QUOTE

I am trying to run a script called f2c with the following formula:

C = (F- 32) 5/9. This is what I have so far:

#! /bin/sh -f
#f2c
TEMP='expr ( $1 - 32\) \* 5/9'
echo "The Celsius temp is: ${TEMP}"

Does this look correct to you. When I type f2c in the command prompt I get:

The Celsius temp is: ${TEMP}

Thanks in advance for your help.



is it a single quote you are using for 'expr...' ?? you should try backquote ` ....
I am using a single quote, but when I use the backquote `, I get a syntax error.This is the correct syntax: #! /bin/sh -f
#f2c
TEMP=$[ ( $1 - 32 ) * ( 5 / 9 ) ]
echo "The Celsius temp is: ${TEMP}"but it won't do what you expect. Bash/sh evaluates 5/9 to 0 - no decimals.

If you want to do precision arithmetic, tryman bcyou can try this :

Code: [Select]results=$(printf "%s\n" 'scale = 2; ($1-32) * 5/9' | bc)
echo $results


Discussion

No Comment Found