Bash Shell scripting – Arithmetic Expressions in BASH






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

Example:
Run the following commands on terminal:

You can also create a bash script for the above operations. For example we have a script operations.sh

now run the above script

Output:

expr — evaluate expression
we can also use expr command to perform Arithmetic operations on numbers.
For example we have a script operations_expr.sh.

now run the above script

Output:


Partner Sites

VideoToGifs.com

EasyOnlineConverter.com

SqliteTutorials.com


Stuff I use to make videos

Windows notebook – http://amzn.to/2zcXPyF

Apple MacBook Pro – http://amzn.to/2BTJBZ7

Desktop - http://amzn.to/2zct252

Microphone – http://amzn.to/2zcYbW1

notebook mouse – http://amzn.to/2BVs4Q3

Screen Recording Software – Camtasia