- 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
推薦閱讀
- 零基礎(chǔ)學(xué)Visual C++第3版
- 精通JavaScript+jQuery:100%動(dòng)態(tài)網(wǎng)頁(yè)設(shè)計(jì)密碼
- 觸·心:DT時(shí)代的大數(shù)據(jù)精準(zhǔn)營(yíng)銷
- Visual C++程序設(shè)計(jì)學(xué)習(xí)筆記
- Docker技術(shù)入門(mén)與實(shí)戰(zhàn)(第3版)
- Android和PHP開(kāi)發(fā)最佳實(shí)踐(第2版)
- 我的第一本算法書(shū)
- 程序員考試案例梳理、真題透解與強(qiáng)化訓(xùn)練
- Python爬蟲(chóng)開(kāi)發(fā)與項(xiàng)目實(shí)戰(zhàn)
- 自然語(yǔ)言處理Python進(jìn)階
- SQL Server 2016數(shù)據(jù)庫(kù)應(yīng)用與開(kāi)發(fā)
- Visual C#通用范例開(kāi)發(fā)金典
- Python全棧數(shù)據(jù)工程師養(yǎng)成攻略(視頻講解版)
- 編寫(xiě)高質(zhì)量代碼:改善Objective-C程序的61個(gè)建議
- Scala編程實(shí)戰(zhàn)