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







免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM