Conditional logic and variable evaluation

Shell scripts would not be very useful if they did not include logic and control capabilities such as if and while.

An if block takes the form:

if expression; then
     commands
[else
     commands ]
fi

For example:

if [[ $var1 = $var2 ]]; then
     echo True:
     echo The two variables match.
else
     echo False
     echo The two variables do not match.
fi

Be careful about numerical comparison: -eq,-lt,-gt are for math, =,<,> are for characters. For example:

[[ 10 -lt 20]] versus [[ ten < twenty]]





Matt Disney 2005-09-14