跳转至

5. case

5.1 猜数字游戏

vim guess_num.sh
#!/bin/bash
read -p "please input a number:" num
case "$num" in
    1)
        echo "the number you input is $num"
        ;;
    [2-5])
        echo "the number you input is $num of [2-5]"
        ;;
    [6-9])
        echo "the number you input is $num of [6-9]"
        ;;
    *)
        echo "the number you input is not in [1-9]"
        exit 1;
esac

最后更新: 2022-02-19 13:59:07