{ads}

Creating a quick calculation function on Linux



April 18, 2022 at 09:48PM

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.

To read this article in full, please click here



from Network World https://ift.tt/YXniTy2

0 Response to "Creating a quick calculation function on Linux"

Post a Comment

Article Top Ads

Central Ads Article 1

Middle Ads Article 2

Article Bottom Ads