zoukankan      html  css  js  c++  java
  • shell流程控制

    if

    if condition
    then
        command1 
        command2
        ...
        commandN 
    fi

    if else

    if condition
    then
        command1 
        command2
        ...
        commandN
    else
        command
    fi

    if else-if else

    if condition1
    then
        command1
    elif condition2 
    then 
        command2
    else
        commandN
    fi

    for

    while

    until

    case

    [root@ipha-dev71-1 exercise_shell]# cat test.sh 
    #!/bin/sh
    echo "输入1到4之间的数字:"
    echo "你输入的数字为:"
    read aNum
    case $aNum in
        1) echo '你选择了1'
        ;;
        2) echo '你选择了2'
        ;;
        3) echo '你选择了3'
        ;;
        4) echo '你选择了4'
        ;;
        *) echo '你没有输入1到4之间的数字'  # 如果无一匹配模式,使用星号 * 捕获该值,再执行后面的命令
        ;;
    esac
    [root@ipha-dev71-1 exercise_shell]# ./test.sh 
    输入1到4之间的数字:
    你输入的数字为:
    3
    你选择了3
    [root@ipha-dev71-1 exercise_shell]# ./test.sh 
    输入1到4之间的数字:
    你输入的数字为:
    6
    你没有输入1到4之间的数字

    break:跳出所有循环(终止执行后面的所有循环)

    continue:跳出当前循环

  • 相关阅读:
    2017年3月9日上午学习
    3.17上午
    3.16上午
    3.16下午
    3.15
    2017.3.14
    3.14
    217.3.13上午
    2017.4.7-morning
    2017.4.6-afternoon
  • 原文地址:https://www.cnblogs.com/wang-mengmeng/p/11425112.html
Copyright © 2011-2022 走看看