- 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
推薦閱讀
- Getting Started with Citrix XenApp? 7.6
- OpenDaylight Cookbook
- Flask Blueprints
- LabVIEW2018中文版 虛擬儀器程序設計自學手冊
- 簡單高效LATEX
- Java程序員面試算法寶典
- Java:Data Science Made Easy
- Apex Design Patterns
- GeoServer Beginner's Guide(Second Edition)
- Learning Apache Mahout Classification
- Mathematica Data Analysis
- Java 從入門到項目實踐(超值版)
- Building Slack Bots
- Access數據庫應用教程(2010版)
- Groovy 2 Cookbook