首页 > 代码库 > Shell编程 之 多分支case语句

Shell编程 之 多分支case语句

1. 结构

  技术分享

2. 案例

#!/bin/bash

echo "wayne : input 1"
echo "echo  : input 2"
echo "we    : input 3"

read -t 30 -p "input your choice: " cho

case "$cho" in
        "1")
                echo "wayne love echo"
                ;;
        "2")
                echo "echo love wayne"
                ;;
        "3")
                echo "we love ew"
                ;;
        *)
                echo "no no no"
                ;;
esac
~                                                                           
~                                                                           
~                                                                                                                                                   
"case2.sh" 22L, 274C

 

#!/bin/bash

read -t 30 -p "input yes or no: " cho

case "$cho" in
        "yes")
                echo "your input is yes"
                ;;
        "no")
                echo "your input is no"
                ;;
        *)
                echo "invalid inputs" 
                ;;
esac
~                                                                           
~                                                                           
~                                                                                                                                                    
"case1.sh" 15L, 184C

  

Shell编程 之 多分支case语句