In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-09-22 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >
Share
Shulou(Shulou.com)06/01 Report--
This article shows you what are the five methods of arithmetic operations in the Linux terminal. The content is concise and easy to understand, which can definitely brighten your eyes. I hope you can get something through the detailed introduction of this article.
We will show you a variety of useful ways to perform arithmetic operations in Linux terminals. At the end of this article, you will learn the basic different practical methods of doing mathematical calculations on the command line.
Let's get started!
1. Use Bash Shell
The 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.
The market share of Chrome browser on the desktop has exceeded 70%, and users are complaining about
The world's first 2nm mobile chip: Samsung Exynos 2600 is ready for mass production.According to a r
A US federal judge has ruled that Google can keep its Chrome browser, but it will be prohibited from
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
About us Contact us Product review car news thenatureplanet
More Form oMedia: AutoTimes. Bestcoffee. SL News. Jarebook. Coffee Hunters. Sundaily. Modezone. NNB. Coffee. Game News. FrontStreet. GGAMEN
© 2024 shulou.com SLNews company. All rights reserved.