Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to do real calculation in sh 1

Status
Not open for further replies.

crasho2001

Technical User
Jun 13, 2002
51
TR
Hi,

In a shell script, I am dividing some numbers with expr.

expr 48 / 10 .... But the result is 4.

How can I get correct result 4.8 ....

Regards.
 
hard in the shell, use bc

echo "scale=2;48.0/10"|bc ------------ jamisar
Einfachheit ist das Resultat der Reife. (Friedrich Schiller)
Simplicity is the fruit of maturity.
 
Hi:

If you are using only the Bourne, sh, Jamisar's bc solution is correct. The '93 version of Korn supports floating point arithmetic.

On my Solaris 7 box, it's the desk top ksh:

#!/usr/dt/bin/dtksh

x=$((48 / 10.0))
echo $x # should be 4.8

 
Einstein:

In another thread, you asked how dickie and others are posting threads. Not to elaborate on the obvious, but simply cuting and pasting, or simply typing it in, is what I do:

thread822-357314

I've had trouble with the link when the thread was not on a line by itself. I don't know how dickie does it.

I've started keeping a file with my favorite tek-tip solutions and faqs, so I can readily cut and paste the link.

Regards,

Ed
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top