In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-03-29 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/01 Report--
In this article Xiaobian for you to introduce in detail "what are the commonly used calculators on the Linux command line", the content is detailed, the steps are clear, and the details are handled properly. I hope that this article "which calculators are commonly used on the Linux command line" can help you solve your doubts.
1) bc
Bc is an interactive instruction by default. In the bc working environment, the following calculation symbols can be used: + addition-subtraction * multiplication / division ^ exponential% remainder such as:
**
3, 4, 5, 2, 5, 2, 18, 4, 710254quit.
# bcscale=3 1/3.333quit
The above is the interactive calculation, so the result can be calculated directly without interaction.
a. Use echo and | methods, such as:
# echo "(6x3) * 2" | bc18
# echo 15swap 4 | bc3
# echo "scale=2;15/4" | bc3.75
# echo "3, 3, 4, 10, 2, 5, 2, 18, 4" | bc710254
In addition, bc in addition to scale to set decimal places, there are ibase and obase to other base operations.
Such as:
/ / output hexadecimal A7 to decimal, note that English can only be capitalized
# echo "ibase=16;A7" | bc167
/ / convert binary 11111111 to decimal
# echo "ibase=2;11111111" | bc255
/ / input in hexadecimal and output in binary
# echo "ibase=16;obase=2;B5-A4" | bc10001
There is a supplement to bc, which can also be found in bc-help: bc can be followed by a file name. Such as:
# more calc.txt 3 "24" 58 "210 Universe bc calc.txt 59162
2) expr
Expr command can not only calculate addition, subtraction, multiplication and division, there are many expressions, can calculate the results, but it is important to note that when calculating addition, subtraction, multiplication and division, do not forget to use spaces and escape. Let's directly introduce the operation of expr with an example, such as:
# expr 6 + 3 (with spaces) 9
# expr 2 / * 3 (with escape symbols) 6
# expr 14% 9 5
# a blank expr (no spaces) a + 5 (variables, spaces) 8
# a=expr 4 + 2echo a + 39
In addition, expr is also convenient for string operation (calculation), such as:
/ / string length # expr length "yangzhigang.cublog.cn" 21
/ / grab the string from the location # expr substr "yangzhigang.cublog.cn" 1 11
Yangzhigang
/ / the beginning of the string
# expr index "yangzhigang.cublog.cn" cu13
3) dc
There are not many people who use dc to calculate, because dc is more complex than bc, but when it comes to simple plans, it is similar and not difficult. Dc is a stack pushing operation, which is interactive by default, but you can also use echo and | to match the preparation.
Such as:
# dc32+
P54*p20
Quit
# echo 3 2 + 4 * p | dc20
4) echo
It is well known that echo is used for echo. The above is also calculated with bc. In fact, echo can also do simple calculations alone, such as:
# echo (3) 5) * 2) 16
Echo can also calculate variables, such as:
# ajar 1, please check echo a+a+a+$b | bc15
/ / calculate the date of the day before yesterday
# echo date +% Y%m%d20090813# echo date +% Y%m%d-220090813-matching echo date +% Y%m%d-2 | bc20090811
5) AWK
Awk can perform operations when processing files, and of course, it can also be used only for calculations, such as:
# awk 'BEGIN {aq3 / 2 / print a}' awk 'BEGIN {a = (3 / 2) * 2 / print a}' 10
After reading this, the article "which calculators are commonly used on the Linux command line" has been introduced. If you want to master the knowledge of this article, you still need to practice and use it yourself to understand it. If you want to know more about related articles, 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.