In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-19 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/01 Report--
This article mainly introduces the relevant knowledge of arithmetic operators in shell, the content is detailed and easy to understand, the operation is simple and fast, and it has a certain reference value. I believe you will gain something after reading this article on arithmetic operators in shell. Let's take a look.
The commonly used arithmetic operators are listed below, assuming that the variable an is 10 and the variable b is 20:
Operator states that the result of example + addition expr $a + $b is 30. -subtract expr $a-$b and the result is-10. * multiply expr $a\ * $b and the result is 200. / divide expr $b / an and the result is 2. % take expr $b $an and the result is 0. Assigning a value to b assigns the value of the variable b to a. = = equal. It is used to compare two numbers, and true is returned if the same number is the same. [B] returns false. ! = not equal. It is used to compare two digits. True is returned if they are different. [B] returns true. Example
Examples of arithmetic operators are as follows:
#! / bin/bash# author: rookie tutorial # url:www.runoob.coma=10b=20val= `expr $a + $b`echo "a + b: $val" val= `expr $a-$b`echo "a-b: $val" val= `expr $a\ * $b`echo "a * b: $val" val= `expr $b / $a`echo "b / a: $val" val= `expr $b% $a`echo "b% a: $val" if [$a = $b] thenecho "an equals b" fiif [$a! = $b] thenecho "an is not equal to b" fi
Execute the script, and the output is as follows:
A + b: 30a-b:-10a * b: 200b / a: 2b% a: 0a is not equal to b Note: the multiplication sign (*) must be preceded by a backslash (\) to achieve multiplication; if...then...fi is a conditional statement, which will be explained later. The expr syntax for shell in MAC is: $((expression)), where the "*" in the expression does not need to escape the symbol "\". This is the end of the article on "what are the arithmetic operators in shell?" Thank you for reading! I believe you all have a certain understanding of the knowledge of "what are the arithmetic operators in shell". 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.