Operators

There are various operators supported by each shell. Our tutorial is based on default shell (Bourne) so we are going to cover all the important Bourne Shell operators in the tutorial.

There are following operators which we are going to discuss:

    Arithmetic Operators.

    Relational Operators.

    Boolean Operators.

    String Operators.

    File Test Operators.

The Bourne shell didn't originally have any mechanism to perform simple arithmetic but it uses external programs, either awk or the must simpler program expr.

Here is simple example to add two numbers:

#!/bin/sh

val=`expr 2 + 2`
echo "Total value : $val"

This would produce following result:

Total value : 4

There are following points to note down:

    There must be spaces between operators and expressions for example 2+2 is not correct, where as it should be written as 2 + 2.

    Complete expression should be enclosed between ``, called inverted commas.