Arithmetic Operators: #!/bin/sh
Arithmetic Operators: #!/bin/sh
Arithmetic Operators
Relational Operators
Boolean Operators
String Operators
File Test Operators
Bourne shell didn't originally have any mechanism to perform simple arithmetic
operations but it uses external programs, either awk or expr.
The following example shows how to add two numbers −
Live Demo
#!/bin/sh
val=`expr 2 + 2`
echo "Total value : $val"
Arithmetic Operators
The following arithmetic operators are supported by Bourne Shell.
Assume variable a holds 10 and variable b holds 20 then −
Show Examples
- (Subtraction) Subtracts right hand operand from left `expr $a - $b` will give
hand operand -10
* Multiplies values on either side of the `expr $a \* $b` will
(Multiplication) operator give 200
/ (Division) Divides left hand operand by right hand `expr $b / $a` will give
operand 2
% (Modulus) Divides left hand operand by right hand `expr $b % $a` will
operand and returns remainder give 0