Introducing how to create a command for basic arithmetic calculations in Linux. For beginners. Introducing commands that can be used when you want to do simple addition, multiplication, exponentiation, etc. on the Linux command line.

Let’s implement a command for calculations on Linux.
$ calc 2/3
0
$ calc3 2/3
0.6666666666666666
$ calc 2**10
20190324142810
$ calc3 2**10
20190324142810
Implemented with Python language.
If you haven’t already, install python and python3.
sudo apt install -y python{,3}
You can open a terminal with ctrl+shift+T. Then paste the following script into the ~/.bashrc file, or paste it directly with right-click or ctrl+shift+V.
pythonprint(){ python -c "print($1)" ; }
alias calc='pythonprint'
pythonprint3()
{
python3 -c "print($1)"
}
alias calc3='pythonprint3'
After that, you can do calculations with the calc or calc3 command.
The difference between calc and calc3 is just whether it’s python or python3. Python and python3 have a difference in division: when the result is a decimal (float) number, it’s either truncated to an integer or displayed with decimals. Use calc3 if you want to display decimal places.
Also, since the pythonprint function evaluates Python expressions as they are (it’s exec or eval in other languages), it can be used for purposes other than calculations.
For example, if you want to convert the string abc to uppercase, you use Python’s upper() function, and you can do this from the Linux command line.

$ var=abc
$ pythonprint "\"${var}\".upper()"
ABC