Shell命令_case

语法:

case "变量" in

    "变量1")

        ...

        ;; #输出两个分号

    "变量2")

        ...

      ;; #输出两个分号

    "变量3")

        ...

       ;; #输出两个分号

    *)

         ...

       ;; #输出两个分号

esac


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
#!/bin/bash
 
# Author:James 2016-10-15
 
echo "want to output a,input 1:"
echo "want to output b,input 2:"
echo "want to output c,input 3:"
 
read -t 30 -p "please input your digit:" digit
 
case "$digit" in
        "1")
                echo "output a"
                #输出两个分号
                ;;
        "2")
                echo "output b"
                ;;
        "3")
                echo "output c"
                ;;
        *)
                #其它输入
                echo "output error,please input 1/2/2"
                ;;
esac






posted @ 2016-11-11 13:44    阅读(14447)  评论(0编辑  收藏  举报