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

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
主站蜘蛛池模板: 阳朔县| 洞头县| 南充市| 双流县| 嵊州市| 临沧市| 介休市| 阜宁县| 彝良县| 徐闻县| 连云港市| 洛扎县| 九龙县| 潮州市| 蕉岭县| 灌南县| 洪湖市| 蓬莱市| 察哈| 乐陵市| 施秉县| 海安县| 乳山市| 元谋县| 准格尔旗| 长沙市| 岳普湖县| 张家川| 高碑店市| 杂多县| 大城县| 深州市| 延边| 湄潭县| 延边| 秭归县| 滨海县| 津市市| 巴楚县| 乐昌市| 贺州市|