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."
fiExample 37.4, “Using arrays and other miscellaneous trickery
to deal four random hands from a deck of cards” and Example 17.11, “Backlight: changes
the brightness of the (laptop) screen backlight”
demonstrate nested if/then condition
tests.