Shell Scripting Tutorial for Beginners 10 - Perform arithmetic operations

preview_player
Показать описание


The Arithmetic expression is very important feature for performing number arithmetic operations in scripts.
By default variables are treated as strings in bash scripts.
But parsing a string to numbers is very easy using double parentheses and external command such as expr.

Arithmetic operations in Bash Shell
Arithmetic operations can be done on integers using the following methods

$(( expression ))
echo "Addition = $(( number_1 + number_2 ))"

expr — evaluate expression
we can also use expr command to perform Arithmetic operations on numbers.

echo "Addition = $(expr $number_1 + $number_2 )"

★★★Top Online Courses From ProgrammingKnowledge ★★★

★★★ Online Courses to learn ★★★

★★★ Follow ★★★

DISCLAIMER: This video and description contains affiliate links, which means that if you click on one of the product links, I’ll receive a small commission. This help support the channel and allows us to continue to make videos like this. Thank you for the support!
Рекомендации по теме
Комментарии
Автор

Do you have any video which explains about error handling in arithmetic expressions ? For example: divide by 0, etc

raghavendramaiyabc
Автор

operations work using squared brackets too.

giorgostsilivis
Автор

weird...when i use expr command, no results return...

lilacding
Автор

if the user want to give the values for num1 and num2 means how can we do that

veesamchaitanya
Автор

The above links is not working...
I want to learn aws tryong to click above link bit it not works..
Let me know how to co tact

sandur
Автор

It says "expr: non-integer argument" for when i do modulus operation using expr. Why?

lozcast
Автор

Why escape character is needed for the asterisk?

nomad
Автор

how to add 1.5e-10 and 4.27e-08 in shell script?

surusvillage
Автор

is it just me or is bash syntax just pure pain (coming from java)

MikeLitoris