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.


8 visits (1 today, 8 this week, 8 this month, 8 this year)
Uptime: 01:49:03 up 1 day, 19:16, 2 users, load average: 0.05, 0.03, 0.01
216.73.216.44 GET from server z.larryforalaska.com

Thursday, March 19, 2026 @ 1:49:03 AM
z.ServerAdmin@lamurakami.com