Tutorial by Examples

dc is one of the oldest language on Unix. It is using the reverse polish notation, which means that you are first stacking numbers, then operations. For example 1+1 is written as 1 1+. To print an element from the top of the stack use command p echo '2 3 + p' | dc 5 or dc <<< '2 3...
bc is an arbitrary precision calculator language. It could be used interactively or be executed from command line. For example, it can print out the result of an expression: echo '2 + 3' | bc 5 echo '12 / 5' | bc 2 For floating-post arithmetic, you can import standard library bc -l: echo ...
Arithmetic computation can be also done without involving any other programs like this: Multiplication: echo $((5 * 2)) 10 Division: echo $((5 / 2)) 2 Modulo: echo $((5 % 2)) 1 Exponentiation: echo $((5 ** 2)) 25
expr or Evaluate expressions evaluates an expression and writes the result on standard output Basic arithmetics expr 2 + 3 5 When multiplying, you need to escape the * sign expr 2 \* 3 6 You can also use variables a=2 expr $a + 3 5 Keep in mind that it only supports integers, so exp...

Page 1 of 1