case语句

case 判断 语句

#!/bin/bash
read -p "press some key, then press return:" KEY
case $KEY in
    [a-z]|[A-Z])
    echo "it is a letter"
    exit 1
    ;;
    [0-9])
    echo "it is a digit"
    exit 1
    ;;
    *)
    echo "it is function keys,Spacebar or other keys."
    exit 1
    ;;    
esac
case 嵌套

#!/bin/bash
##相互嵌套
read -p "果果,告诉妈妈今天想吃什么呀?  (香蕉|苹果|橘子|不想吃):" eat
case $eat in
    香蕉|苹果|橘子)
    echo "妈妈,我想吃$eat!"
    exit 1
    ;;
    不想吃)
    read -p "那你想喝什么呀?(酸奶|白开水|纯奶|瓶瓶):" drink
    case $drink in
        酸奶|白开水|纯奶|瓶瓶)
        echo "妈妈,我想喝$drink!"
        exit 1
        ;;
    esac
    ;;
    *)
    echo "果果,那你到底想干什么呀,可不可以告诉妈妈呀?"
    exit 1
    ;;
esac

 




 

posted @ 2017-12-07 11:18  左丿仔  阅读(231)  评论(0编辑  收藏  举报