例子3:嵌套
效果图,判断是否富有与帅
代码如下:
read -p "Are you rich: " ANSWER
if [[ "$ANSWER" =~ [Y|y]([E|e][S|s])? ]];then
echo "OK!"
elif [[ "$ANSWER" =~ [N|n][O|o]? ]];then
read -p "Are you handsome: " ANSWER
if [[ "$ANSWER" =~ [Y|y]([E|e][S|s])? ]];then
echo "OK!"
elif [[ "$ANSWER" =~ [N|n][O|o]? ]];then
echo "work hard!"
fi
else echo "Your answer is wrong!"
fi
![富有与帅.png](https://upload-images.jianshu.io/upload_images/10967676-cf3e4b0f66abe767.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)