Nested if/then Condition Tests

7.4. Nested if/then Condition Tests

Condition tests using the if/then construct may be nested. The net result is equivalent to using the && compound comparison operator.

a=3

if [ "$a" -gt 0 ]
then
  if [ "$a" -lt 5 ]
  then
    echo "The value of \"a\" lies somewhere between 0 and 5."
  fi
fi

# Same result as:

if [ "$a" -gt 0 ] && [ "$a" -lt 5 ]
then
  echo "The value of \"a\" lies somewhere between 0 and 5."
fi

Example 34-4 demonstrates a nested if/then condition test.


30 visits (3 today, 5 this week, 18 this month, 30 this year)
Uptime: 22:26:25 up 11 days, 23:38, 3 users, load average: 0.24, 0.14, 0.10
216.73.216.115 GET from server z.larrymurakami.com

Wednesday, October 14, 2026 @ 10:26:25 PM
z.ServerAdmin@lamurakami.com