- 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
推薦閱讀
- Hands-On Machine Learning with scikit:learn and Scientific Python Toolkits
- C# Programming Cookbook
- R語言游戲數據分析與挖掘
- 青少年美育趣味課堂:XMind思維導圖制作
- SSM輕量級框架應用實戰
- Hands-On Swift 5 Microservices Development
- 從0到1:Python數據分析
- Windows Embedded CE 6.0程序設計實戰
- Python3.5從零開始學
- HTML+CSS+JavaScript網頁設計從入門到精通 (清華社"視頻大講堂"大系·網絡開發視頻大講堂)
- Building Serverless Web Applications
- Python趣味編程與精彩實例
- Maven for Eclipse
- Android嵌入式系統程序開發(基于Cortex-A8)
- Java Web開發教程:基于Struts2+Hibernate+Spring