Hi,
I am trying to do a percentage calculation in a Bourne shell script. The following works fine, but when I try to subsitute the values 153824 and 246000 for variables (e.g. used and limit), I get errors.
calc()
{
awk 'BEGIN {OFMT="%f"; print '"$*"'; exit}'
}
calc '(153824 / 246000) * 100'
Can some one please help me with whatever it is that I am missing?
Thanks!
sauron
April 18, 2009, 12:18pm
2
hi,
you need to quote the variables:
calc()
{
awk 'BEGIN {OFMT="%f"; print '"$*"'; exit}'
}
VAR1=20
VAR2=30
calc '('$VAR1' / '$VAR2') * 100'
Bye
shorehil:
Hi,
I am trying to do a percentage calculation in a Bourne shell script. The following works fine, but when I try to subsitute the values 153824 and 246000 for variables (e.g. used and limit), I get errors.
calc()
{
awk 'BEGIN {OFMT="%f"; print '"$*"'; exit}'
}
calc '(153824 / 246000) * 100'
Can some one please help me with whatever it is that I am missing?
calc "($used / $limit) * 100"
Hello sauron, cfajohnson,
Both methods worked! Thank you. This is my first time using a forum so you have made this a positive experience.