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

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
主站蜘蛛池模板: 张家港市| 湖州市| 新绛县| 长海县| 双流县| 安吉县| 石嘴山市| 应城市| 汉寿县| 道真| 翼城县| 全州县| 新民市| 上饶县| 张北县| 惠安县| 南漳县| 固原市| 平度市| 建始县| 贺州市| 潞西市| 峨山| 沙田区| 安泽县| 曲松县| 陆河县| 灌云县| 黑龙江省| 遂昌县| 左云县| 辽源市| 邢台市| 沙雅县| 确山县| 牙克石市| 邛崃市| 武宣县| 张家口市| 桂平市| 金昌市|