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!

expr vs. bc for simple math.

Status
Not open for further replies.

Dorga

MIS
Jul 30, 2003
101
NZ
Hi,

I find myself in a situation where I can not use bc as I have been in various scripts to perform simple math, + - * /.

I am now porting my scripts over to a cygwin environment and it looks like my option is, well. expr. Unfortunatly I had been using scale=3 in bc for 100.000% type returns, in expr I have yet to find a way to get this done.

Is there a way, and if not in expr, how can you get awk to return an answer for math with out needing to hit CTRL-D.

Thanks,
 
Why have you to hit Ctrl+D to get awk math result ?

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
PHV,

Most likely because I do not know the proper way to get the reaction. =) Here is what I have come up with, and is also when I have to CTRL-D out after hitting any key to get the answer.

awk '{print 100-35/3072*100}'

feherke,

No, bc works fine, the problem is, the systems I am trying to port to do not have bc, my options are expr, and awk.

Thanks guys!

 
feherke,

That works, thanks, while you were typing, I was diging around and also found this..

echo 100 35 3072 | awk '{printf("%12.2f\n",$1-$2/$3*$2)}'

Thanks again guys!
 
stetanwagner,

No, it is not apple, they are various installs of one type of MS or another with cygwin. Installing anything else even bc was not an option.

People love to make things harder than needed =-)
 
stefan

OS X has bc

Panther comes up with this:-

bc 1.05
Copyright 1991, 1992, 1993, 1994, 1997, 1998 Free Software Foundation, Inc.
This is free software with ABSOLUTELY NO WARRANTY.
For details type `warranty'.

... just in case you were curious!


Kind Regards
Duncan
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top