Last active
March 29, 2022 19:55
-
-
Save VladSavitsky/86331eb62d0504844d8b8d3f49da05f6 to your computer and use it in GitHub Desktop.
Tiny Pure BASH Calulator
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# CLI Calculator. | |
# | |
# Install: Add to .bashrc. | |
# | |
# Usage: '$ = 10*33' | |
# See: https://askubuntu.com/questions/378661 | |
# | |
# Installation: Put code to .bashrc or .bash_aliases. | |
# | |
# Functions: | |
# sqrt ( expression ) The value of the sqrt function is the square root of the expression. | |
# s (x) The sine of x, x is in radians. | |
# c (x) The cosine of x, x is in radians. | |
# a (x) The arctangent of x, arctangent returns radians. | |
# l (x) The natural logarithm of x. | |
# e (x) The exponential function of raising e to the value x. | |
# j (n,x) The Bessel function of integer order n of x. | |
# Function's usage example: = "sqrt(33)" | |
=() { | |
# Simple caluclator: echo "$(($@))" | |
# Using 'bc' | |
local IFS=' ' | |
local calc="${*//p/+}" | |
calc="${calc//x/*}" | |
local result=$(bc -l <<<"scale=10;$calc") | |
env LC_ALL=en_US.UTF-8 printf "%'.3f\n" $result | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment