zoukankan      html  css  js  c++  java
  • shell 模式匹配:case

    case 变量 in

    模式1)

      命令序列1

      ;;

    模式2)

      命令序列2

      ;;

    模式3)

      命令序列3

    *)

      无匹配后命令序列

    easc

    [root@localhost ~]# cat postfix.sh 
    #!/usr/bin/env bash
    #start|stop|restart postfix
    case "$1" in
    start)
        service postfix start
        echo "start postfix"
        ;;
    stop)
        service postfix stop
        echo "stop postfix"
        ;;
    status)
        service postfix status
        ;;
    *)
        echo "Usage:`basename $0` start|stop|status"
    esac
    [root@localhost ~]# cat mysql_install.sh 
    #!/usr/bin/env bash
    #install mysql 
    #v1.0 by time.catcher
    echo "#############################"
    echo -e "	1 mysql5.5"
    echo -e "	2 mysql5.6"
    echo -e "	3 mysql5.7"
    read -p "version[1-3]" version
    case "$version" in
    1)
        echo "install mysql-5.5"
        ;;
    2)
        echo "install mysql-5.6"
        ;;
    3)
        echo "install mysql-5.7"
        ;;
    *)
        echo "Usage please input number[1-3]"
    esac
    #!/usr/bin/env bash
    #delete user
    #v1.0 by time catcher
    
    read -p "Please input username:" user
    id $user &>/dev/null
    if [ $? -nq 0 ];then
            echo "error"
            exit 1
    fi
    
    read -p "Are you sure yes/no" Action
    
    case $Action in
    yes|YES|y|Y)
            userdel $user
            echo "$user is deleted"
            ;;
    *)
            echo "error"
    esac
    #!/usr/bin/env bash
    #jump server
    #v1.0 by time.catcher
    
    cat <<-EOF
        1.web1
        2.web2
        3.web3
    EOF
    
    read -p "please input number: " number
    
    case $number in
    1)
        ssh root@192.168.244.130
        ;;
    2)
        ssh root@192.168.244.131
        ;;
    3)    ssh root@192.168.244.132
        ;;
    *)    
        echo    "error"
        ;;
    esac
  • 相关阅读:
    Hello World
    查找字符串 fiand
    stdou,write与print()
    python 中 按位 与 & ,| ,^ ,~,
    3*3元素主对角元素之和
    Python random() 函数
    文本颜色设计
    if __name__=="__main__
    join函数
    ProGAN论文的翻译+学习体会
  • 原文地址:https://www.cnblogs.com/weiwenbo/p/6725059.html
Copyright © 2011-2022 走看看