Math with bash

must be in double quotes * / % – +

echo “$(( 81712196 / 1024 ))”

79797

echo “$(( 81712196 * 1024 ))”

83673288704

echo “$(( 81712196 % 1024 ))”

68

OR pipe it through bc

echo ‘scale=6; 12*613-894/3.5’ | bc and the answer is 7100.571429

OR

echo “scale=6; (3*3-6+4*5-2)/7*2” | bc -i
bc 1.06.95
Copyright 1991-1994, 1997, 1998, 2000, 2004, 2006 Free Software Foundation, Inc.
This is free software with ABSOLUTELY NO WARRANTY.
For details type `warranty’.
scale=6; (3*3-6+4*5-2)/7*2
6.000000

OR

Simply use tcalc…

Leave a Reply

Your email address will not be published. Required fields are marked *