zoukankan      html  css  js  c++  java
  • shell选择和循环语句

    调用脚本$();

    if语句:

    if[ -d ];then

    xxx

    else

    xxx

    fi

    case语句:

    case xxx in

    xx)

    xxx

    ;;

    esac

    while语句

    while((xx))

    do 

    xxx

    done

    demo:

    #!/bin/bash
    a=$(uname -r)
    echo $a
    function test_if
    {
    if [ -d /root ];then
    result=""ok""
    printf "ok "
    else
    printf "error "
    result=error
    fi
    }

    function test_if_ret
    {
    printf "%s " $1
    printf "%d " 0xff
    }

    function test_case
    {
    case $1 in
    "ok")
    printf "ok in case "
    ;;
    "error")
    printf "error in case "
    ;;
    esac
    }
    function test_for
    {
    i=0
    while((i<25))
    do
    echo i=$((i++))
    done

    }
    test_if
    ret_if="data"
    ret_if=$(test_if_ret $result)
    echo $result

  • 相关阅读:
    HGE tutorial04
    HGE tutorial03
    HGE tutorial02 plus
    HGE tutorial02
    C 语言实例
    C 语言实例
    C 语言实例
    C 语言实例
    C 语言实例
    C 语言实例
  • 原文地址:https://www.cnblogs.com/under/p/10475403.html
Copyright © 2011-2022 走看看