In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-17 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >
Share
Shulou(Shulou.com)06/01 Report--
This article mainly shows you "how to do arithmetic in the Linux terminal", the content is easy to understand, clear, hope to help you solve your doubts, the following let Xiaobian lead you to study and learn "how to do arithmetic in the Linux terminal" this article.
1. Use Bash Shell
The first and easiest way to perform basic mathematical operations on Linux CLI is to use double parentheses. Here are some examples of how we use values stored in variables:
$ADD=$ ((1 + 2)) $echo $ADD$ MUL=$ (($ADD * 5)) $echo $MUL$ SUB=$ (($MUL-5)) $echo $SUB$ DIV=$ (($SUB / 2)) $echo $DIV$ MOD=$ (($DIV% 2)) $echo $MOD
Algorithms in Linux Bash Shell
two。 Use the expr command
The expr command evaluates the expression and prints the value of the provided expression to standard output. We'll look at different ways to use expr for simple math, compare, increase the value of a variable, and find the length of a string. Here are some examples of simple calculations using the expr command. Note that many operators need to escape or reference shell, such as the * operator (we'll see more in the comparison of expressions).
$expr 3 + 5$ expr 15% 3$ expr 5\ * 3$ expr 5-3$ expr 20 / 4
The basic algorithm of using expr command in Linux
Next, we will show you how to make a comparison. When the expression evaluates to false, expr prints a value of 0, otherwise it prints 1.
Let's look at some examples:
$expr 5 = 3$ expr 5 = 5$ expr 8! = 5$ expr 8\ > 5$ expr 8\ < 5$ expr 8\
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.