Creating a quick calculation function on Linux
Anytime you're planning to do a lot of calculations on a Linux system, you can use the power of bash to create a quick function and then use it repeatedly to do the calculations for you. In this post, we'll look at how this trick works and what you need to be aware of to ensure that your calculations are correct.
Let's start with this mathematical function as an example:
$ ? () { echo "$*" | bc ; }
This command sets up a function that will pass the values and mathematical operators that you provide as arguments to the bc calculator command. Note that to call the function, you simply type a "?" followed by the arguments. In the first example below, the arguments are 1, followed by the multiplication character "*", followed by a 2, a "+" sign and a 3. The result is 5.
from Network World https://ift.tt/YXniTy2
0 Response to "Creating a quick calculation function on Linux"
Post a Comment