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

  • 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
主站蜘蛛池模板: 青河县| 海伦市| 印江| 株洲县| 乃东县| 石狮市| 渑池县| 增城市| 晋江市| 宁强县| 宾阳县| 长丰县| 诸暨市| 通道| 壤塘县| 广昌县| 台北市| 佛山市| 武定县| 长治县| 东安县| 九台市| 银川市| 田林县| 睢宁县| 湖南省| 仁布县| 左权县| 连州市| 木兰县| 会宁县| 丹巴县| 云阳县| 洪江市| 海阳市| 上林县| 冷水江市| 济源市| 永靖县| 福海县| 阿拉善盟|