Do Math From The Command Line

Posted by Weston Ganger on April 09, 2015

I always have a terminal open and sometimes I need to add or multiply some values really quick. So I looked into it and made a bash function so I can do this. Add this to your .bashrc

  awk "BEGIN { print "$1"}"

Be sure to reload your bashrc by running ‘exec bash’ or ‘source ~/.bashrc’ or open a new tab And now when you want to do some math right quick.

math 4.2*6.5
math 56+34

### if using parenthesis be sure to wrap it as a string
math "127/(5*3)"

Hope this helps some of you. See the stack exchange link for more methods

Related External Links:

Posted in Linux and Tagged with linux command-line bash math calc 

Need help on your next project or application?

I specialize in Ruby-on-Rails, AngularJS, Javascript, Bootstrap, and Hybrid Mobile Apps with Cordova & Ionic.

Contact Me

Recommended Posts