Floating-Point Arithmetic in a Csh Script

David Koblas koblas at mips.COM
Mon Apr 18 10:23:56 AEST 1988


In article <1748 at ut-emx.UUCP> you write:
>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
>

You were very close, what you needed to do was something more like this:
	#!/bin/csh
	set x = `bc << END  	\
	scale = 5  		\
	$1 + $2  		\
	END`
	echo $x

-- 
name : David Koblas         place: MIPS Computers Systems                
phone: 408-991-0287         uucp : {ames,decwrl,pyramid,prls}!mips!koblas 



More information about the Comp.unix.questions mailing list