Arithmetic Operators in Unix: In Unix we have capability to add, subtract, multiply, division of arithmetic values.
- + (Addition) – To add values on any side of the operator.
expr $a + $b
- -(Subtraction) – To subtract right hand operand from left hand operand.
expr $a - $b
- *(Multiplication) – To multiply the values on either side of the operator.
expr $a \* $b
* is the special character in Unix and whenever we use special character, we should prefix with the symbol \ .
- / (Division) – To divide the left-hand operand by right hand operand.
expr $b / $a
- % (Modulus) – To divide the left-hand operand by right hand operand and returns remainder
expr $b % $a
- = (Assignment) – To assign the right operand in left operand. The value of b will be assigned to variable a.
a = $b
- == (Equality) – To compare the 2 numbers. If both are same then it will return True else it will return False.
[ $a == $b ]
- != (Not Equality) – To compare the two numbers. If both are different then it will return true.
[ $a != $b ]
In Unix, it is very important to know that all the conditional expressions should be inside the square braces with the space.
[ $a == $b ] is correct.
[$a==$b] is incorrect.