1

Help with Aritmetic calculations in Shell script

view story
linux-howto

http://www.unix.com – Hi, I need a help with arithmetic calculations in my script. I have two variables: a=17; b=1712 I want to perform ($a/$b)*100 with two decimals in the result. I tried with following: Code: res=$((100*a/b)) res=`echo "scale=2; $a / $b" | bc` But I am not getting the decimal values. My expected result for above is 0.99 And while I testing , I encountered with divide by Zero and the script was hangup. Any idea how to avoid this? Thanks! (HowTos)