mathematics_in_bash
no way to compare when less than two revisions
Differences
This shows you the differences between two versions of the page.
Previous revision | |||
— | mathematics_in_bash [2015/12/19 14:59] (current) – external edit 127.0.0.1 | ||
---|---|---|---|
Line 1: | Line 1: | ||
+ | * Math on the cli | ||
+ | < | ||
+ | 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 | ||
+ | |||
+ | $ echo " | ||
+ | -10.48 | ||
+ | |||
+ | using here-doc | ||
+ | |||
+ | $ bc <<< | ||
+ | -10.48 | ||
+ | |||
+ | a bash funtion, for your .bashrc | ||
+ | |||
+ | calc () { | ||
+ | bc -l <<< | ||
+ | } | ||
+ | |||
+ | usage: | ||
+ | |||
+ | $ calc 65320*670 | ||
+ | 43764400 | ||
+ | </ |
mathematics_in_bash.txt · Last modified: 2015/12/19 14:59 by 127.0.0.1