In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-25 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/02 Report--
This article mainly introduces what the commonly used computing tools in Linux have related knowledge, the content is detailed and easy to understand, the operation is simple and fast, and has a certain reference value, I believe you will get something after reading this Linux commonly used computing tools, let's take a look at it.
When using Linux, we sometimes need to do some calculations, so we may need to use a calculator. On the Linux command line, there are many calculator tools that allow us to perform scientific calculations, financial calculations, or some simple calculations. Of course, we can also use these commands in Shell scripts to perform more complex mathematical operations.
Expr
First of all, when it comes to using commands for mathematical operations on the command line, perhaps the easiest and most commonly used command is expr (the expression expression. It can perform four operations, and it can also be used to compare sizes. Here are a few examples:
Variable increment
Mathematical Operation under Linux Command Line Mathematical Operation under Linux Command Line
Complete a simple operation
Note that you need to add a\ symbol before the * operator to avoid syntax errors (Note: * is a wildcard for bash, so it needs to be escaped, and the > below is also escaped because it is a pipe character for bash). The% operator is used for the remainder operation.
Here is a slightly more complex example:
Assuming that there are 11 participants in an event and the total number of awards to be awarded is 156, then each participant receives an average of 14 awards, with 2 additional awards remaining.
Compare
Let's take a look at the comparison operation. At first impression, the statement looks a little weird; instead of setting a numerical value, it's a numerical comparison. In this case, expr determines whether the expression is true: if the result is 1, the expression is true; otherwise, the expression is false.
Please read "is 11 equal to 11?" And "is 11 equal to 12?" You will soon get used to this way of writing. Of course, we will not perform the above comparison on the command line, but the possible comparison is whether $age equals 11. In this example, we determine whether 10 is greater than 5 to
And whether it is greater than 99.
Mathematical Operation under Linux Command Line Mathematical Operation under Linux Command Line
Indeed, returns 1 and 0 indicate that the result of the comparison is true and false, respectively, which we generally expect on Linux. In the following example, using expr according to the above logic is incorrect, because if works on the opposite principle, that is, 0 represents true.
* * next, we run the script: * * below, we run the script:
This is obviously not in line with our expectations! Let's modify it a little bit so that it works as we expect:
Factor
The function of the factor command is basically what you expected. You give a number, and the command gives the factor of the corresponding number.
Note: the factor command does not return more factors for the last number because 1987 is a prime number.
Jot
The jot command creates a series of numbers. Given the total number of numbers and the starting number.
You can also use jot in the following way, where we want to decrement to the number 2.
Jot can help you construct a list of numbers that can be used for other tasks.
Bc
Bc is basically one of the best tools for command-line math. Enter the operation you want to perform and send it to the command using the pipeline:
It can be seen that bc does not ignore precision, and the input string is quite straightforward. It can also compare sizes, manipulate Boolean values, calculate square roots, sinusoids, cosines, tangents, and so on.
In fact, bc can even calculate pi. You need to specify the precision you need.
In addition to receiving data and returning results through a pipeline, bc can run interactively by entering the operations you want to perform. The scale setting mentioned in this example specifies the number of significant digits.
You can also use bc to complete the digital base conversion. Obase is used to set the numeric base of the output.
Using bc as follows is also one of the easiest ways to accomplish hexadecimal to decimal conversion:
In the first example above, we set the input ibase to hexadecimal (hex) to complete the conversion from hexadecimal to decimal. In the second example, we do the opposite, setting the output obase to hexadecimal.
Simple bash mathematical operation
By using double parentheses, we can do simple mathematical operations in bash. In the following example, we create a variable, assign a value to the variable, and then perform addition, self-subtraction, and square.
The operators allowed are:
You can also use logical operators and Boolean operators:
Or as follows:
The following calculates the third power of 2:
This is the end of the article on "what are the commonly used computing tools in Linux?" Thank you for reading! I believe you all have a certain understanding of the knowledge of "what are the commonly used computing tools in Linux". If you want to learn more, you are welcome to follow the industry information channel.
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.