7.4. 嵌套if/then条件测试

使用if/then结构的条件测试可以嵌套。最终结果等同于使用 && 复合比较运算符。

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

例 37-4例 17-11 演示了嵌套的if/then条件测试。