Floating-Point Arithmetic in a Csh Script
Jeff Rodriguez
jjr at ut-emx.UUCP
Mon Apr 18 01:22:26 AEST 1988
I am trying to do floating-point arithmetic in a csh script for 4.3 BSD.
Since "@ x = 2.3 + 4.5" won't work, I'm using bc.
But I can't find a nice way to get bc's output into a shell variable
without using a temporary file.
This method does not work:
#!/bin/csh
set x = `bc << END`
scale = 5
$1 + $2
END
This is the best that I've come up with:
#!/bin/csh
# This csh script computes x = $1 + $2,
# where $1 and $2 are floating-point numbers.
bc << END > temp
scale = 5
$1 + $2
END
set x = `cat temp`
Can anybody think of a better way?
Jeff Rodriguez
jjr at emx.utexas.edu
More information about the Comp.unix.questions
mailing list