8.5 Complex conditionals

There are three methods of making complex conditional expressions:

1. Logical and

2. Logical or

3. Logical not

Logical and

By using the -a operator in a conditional expression, you can require two conditions to hold true for the entire expression to be true. For example, the following code checks to see if the user is between 20 and 40 years of age:

#!/usr/bin/sh

echo "Please enter your age"

read age

if [ $age -gt 20 -a $age -lt 40 ]

then

echo "You are between 20 and 40 years old"

fi

Click here to go back