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

  • 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
主站蜘蛛池模板: 武城县| 普兰县| 霍城县| 阿勒泰市| 江油市| 蓝山县| 临江市| 大理市| 广德县| 清徐县| 永丰县| 壤塘县| 宣化县| 灵山县| 张掖市| 锡林浩特市| 平安县| 兴化市| 电白县| 苍梧县| 旅游| 宿迁市| 铅山县| 将乐县| 习水县| 平乡县| 江山市| 依兰县| 阜宁县| 绥中县| 沾化县| 保靖县| 江源县| 论坛| 吉林省| 齐齐哈尔市| 惠安县| 锡林郭勒盟| 西乡县| 临武县| 洛宁县|