• case 练习


    #!/bin/bash
    
    RED_COLOR="E[1;31m"
    GREEN_COLOR="E[1;32m"
    YELLOW_COLOR="E[1;33m"
    BLUE_COLOR="E[1;34m"
    RES="E[0m"
    
    function usage(){
            echo "USAGE: $0 {1|2|3|4}"
            exit 1
    }
    
    function menu(){
            cat << END
                    =============================
                    1.apple
                    2.pear
                    3.banana
                    4.cherry
                    =============================
    END
    }
    
    
    function choice(){
    read -p "Please input a number to choice." num
    case $num in
            1)
                    echo -e "${RED_COLOR}apple${RES}"
                    ;;
            2)
                    echo -e "${GREEN_COLOR}pear${RES}"
                    ;;
            3)
                    echo -e "${YELLOW_COLOR}banana${RES}"
                    ;;
            4)
                    echo -e "${BLUE_COLOR}cherry${RES}"
                    ;;
            *)
                    usage
    esac
    }
    
    function main(){
            menu
            choice
    }
    main
  • 相关阅读:
    while循环
    三元运算符
    switch用法
    if判断
    位运算
    逻辑运算符
    赋值运算符和比较运算符
    算术运算符
    数据类型的转换
    线程同步之(条件变量)
  • 原文地址:https://www.cnblogs.com/vincenshen/p/6594584.html
Copyright © 2020-2023  润新知