Wednesday, February 2, 2011

bc linux command

You may be using bc command in command line for calculations. It can also be used for batch mode calculations as explained below.


Syntax
bc [-c] [-l] [file]




To perform addition using bc command

echo "56.8 + 77.7" | bc




Another way of executing bc calculation

bc <<< 4+2




Let say you want to convert decimal to hexadecimal, you can do this.
echo "obase=16; ibase=10; 56" | bc




A simply way to do calculation with floating point
echo 2/5 | bc -l

No comments:

Post a Comment