官术网_书友最值得收藏!

  • Bash Cookbook
  • Ron Brash Ganesh Naik
  • 96字
  • 2021-07-23 19:17:29

Nested if statements

If a single level of if statements is not enough and you would like to have additional logic within an if statement, you can create nested conditional statements. This can be done in the following way:

#!/bin/bash
USER_AGE=18
AGE_LIMIT=18
NAME="Bob" # Change to your username if you want to execute the nested logic
HAS_NIGHTMARES="true"

if [ "${USER}" == "${NAME}" ]; then
if [ ${USER_AGE} -ge ${AGE_LIMIT} ]; then
if [ "${HAS_NIGHTMARES}" == "true" ]; then
echo "${USER} gets nightmares, and should not see the movie"
fi
fi
else
echo "Who is this?"
fi
主站蜘蛛池模板: 桃园县| 林周县| 南投县| 青冈县| 海门市| 三门县| 囊谦县| 枝江市| 龙南县| 寻甸| 盐源县| 永春县| 哈巴河县| 星子县| 永清县| 荥经县| 靖宇县| 通山县| 澎湖县| 东至县| 汉寿县| 红河县| 呼图壁县| 焉耆| 读书| 镇江市| 雷州市| 白玉县| 城市| 栾城县| 大连市| 西丰县| 黑龙江省| 吉林省| 霍山县| 龙井市| 东海县| 车致| 额敏县| 酒泉市| 乌鲁木齐县|