User Tools

Site Tools


mathematics_in_bash

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

mathematics_in_bash [2015/12/19 15:59] (current)
Line 1: Line 1:
 +* Math on the cli
 +<​code>​
  
 +Basic operations
 +
 +$ echo $((1+1))
 +2
 +$ echo $((3-1))
 +2
 +$ echo $((4/2))
 +2
 +$ echo $((1*2))
 +2
 +
 +Basic ops using expr
 +
 +$ expr 60 / 5
 +12
 +
 +Floating point calculations
 +
 +$ echo "​2*2.2/​2.2"​ | bc
 +2
 +
 +$ echo "​4.4+7/​8-(4.74*3.14)"​ | bc
 +-10.48
 +
 +using here-doc
 +
 +$ bc <<<​ "​4.4+7/​8-(4.74*3.14)"​
 +-10.48
 +
 +a bash funtion, for your .bashrc
 +
 +calc () {
 +    bc -l <<<​ "​$@"​
 +}
 +
 +usage:
 +
 +$ calc 65320*670
 +43764400
 +</​code>​
mathematics_in_bash.txt ยท Last modified: 2015/12/19 15:59 (external edit)