Validating parameters using conditional statements
Variables can be tested and compared against other variables when using a variable as a number.
Here is a list of some of the operators that can be used:
Operator |
Description |
---|---|
|
This stands for equal to |
|
This stands for not equal to |
|
This stands for greater than |
|
This stands for less than |
|
This stands for greater than or equal to |
|
This stands for less than or equal to |
|
This stands for the negation operator |
Let's take a look at this in our next example script:
Chapter 2 - Script 2
#!/bin/sh # # 6/13/2017 # echo "script2" # Numeric variables a=100 b=100 c=200 d=300 echo a=$a b=$b c=$c d=$d # display the values # Conditional tests if [ $a -eq $b ] ; then echo a equals b fi if [ $a -ne $b ] ; then echo a does not equal b fi if [ $a -gt $c ] ; then echo a is greater than c fi if [ $a -lt $c ] ; then echo a is less than c fi if [ $a -ge $d ] ; then echo a is greater than...