Published on March 16, 2017 by ProgrammingKnowledge

For more detailed Tutorial visit – goo.gl/ZrJh1a

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 )”

My Website – www.codebind.com
My Blog – goo.gl/Nd2pFn
My Facebook Page – goo.gl/eLp2cQ
Google+ – goo.gl/lvC5FX
Twitter – twitter.com/ProgrammingKnow
Pinterest – goo.gl/kCInUp
Text Case Converter – goo.gl/pVpcwL
Epoch Timestamp Converter – goo.gl/Zedjo5
Decimal – Binary – Hexadecimal Converter – goo.gl/rkX3JE
8-bit Checksum Calculator – goo.gl/inxvIT

Leave a Reply

2 Comments on "Shell Scripting Tutorial for Beginners 10 – Perform arithmetic operations"

Notify of
avatar

trevor zvidza
Guest
trevor zvidza
7 days 21 hours ago

can l ask you something

ProgrammingKnowledge
Guest
ProgrammingKnowledge
8 days 19 hours ago

For more detailed Tutorial visit – goo.gl/ZrJh1a

wpDiscuz