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.


32 visits (2 today, 2 this week, 18 this month, 32 this year)
Uptime: 15:50:50 up 3 days, 5:34, 1 user, load average: 0.00, 0.00, 0.00
216.73.217.130 GET from server z.lam1.us

Sunday, August 23, 2026 @ 3:50:50 PM
z.ServerAdmin@lamurakami.com