bash arithmetic

From thelinuxwiki
Revision as of 17:04, 23 August 2013 by Nighthawk (Talk | contribs)

Jump to: navigation, search

using let

let "TOTAL = ( $A + 5 ) / $b"


floating point using bc

TOTAL=`echo "( $A + 5 ) / $b" | bc -l

using scale to control number of digits

$ echo "1 / 100" | bc -l 
.01000000000000000000

$ echo "scale =2; 1 / 100" | bc -l                                                                        ~
.01


using expr

a=`expr $a + 1`
a=`expr 5 + 3`