Linux and Networking

Linux and Networking

4.14. Comparisons of integers.

Shell script has many operators with which you can construct integer comparison expressions. Let’s see which are the most common:

 

-eq. is equal to (equal)

If [ “$a” -eq “$b” ]

 

-ne. It is not equal to (not equal)

If [ “$a” -ne “$b” ]

 

-gt. Greater than (greater than)

If [ “$a” -gt “$b” ]

 

-ge. Greater or equal (greater or equal)

If [ «$a» -ge «$b» ]

 

-lt. Less than

If [ «$a» -lt «$b» ]

 

-you. Less than or equal to (less or equal)

If [ «$a» -le «$b» ]

 

< Less than. To use this operator we need to use a double parenthesis.

((«$a»)<(“$b”))

 

<= Less than or equal to. To use this operator we need to use a double parenthesis.

((«$a»)<=(“$b”))

 

> Greater than. To use this operator we need to use a double parenthesis.

((«$a»)>(«$b»))

 

>= Greater than or equal to. To use this operator we need to use a double parenthesis.

((«$a»)>=(«$b»))

The Demeter Project