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.


200 visits (1 today, 7 this week, 33 this month, 200 this year)
Uptime: 11:33:35 up 10 days, 17:17, 5 users, load average: 0.02, 0.02, 0.00
18.221.93.44 GET from server z.larryforalaska.com

Saturday, December 28, 2024 @ 11:33:35 AM
z.ServerAdmin@lam1.us