• Bash Excercises


    1. cat <<EOF

    #!/bin/bash
    function printHelp {
    cat<<EOF
    
    Run the Dash vector tests.
    Usage:
    ./run_dash_vector_test.sh <vector_env> <dash_version>
    
    The vector environment should be the value 1 or 2, to indicate which of the
    static Dash vector environments should be used.
    
    The Dash version should be a valid git revision, e.g. 'master' or
    '2.3352-HOTFIX'.
    
    EOF
    }
    
    if [[ "$#" -ne 2 ]]
    then
    printHelp
    exit -1
    fi

    2. let i++
    reference:
    [1] http://askubuntu.com/questions/385528/how-to-increment-a-variable-in-bash

    #!/bin/bash
    let i=1
    for SCRIPTLET in "${SCRIPTLETS[@]}"
    do
    echo " ${i}) ${SCRIPTLET}"
    let i++
    done

    The same as:

    #!/bin/bash
    i=0
    while [ "$i" -lt 10 ]
    do
    <command block>
    i=`expr $i + 1`
    done

    or even

    #!/bin/bash
    i=0
    while [ "$i" -lt 10 ]
    do
    <command block>
    (( i = i + 1 )) # or (( i+=1 ))
    done

     3. getopts

    #!/bin/bash
    while getopts ":d:e:g:v:" opt
    do
      case $opt in
        d) DASH_REVISION="$OPTARG" ;;
        e) EMAIL="$OPTARG" ;;
        g) GIT_DIR="$OPTARG" ;;
        v) VECTOR_ENV="$OPTARG" ;;
        ?) echo "Invalid option: -$OPTARG" >&2; exit -1 ;;
      esac
    done
  • 相关阅读:
    Vue-dialog(弹框组件)
    Vue封装select下拉组件
    RAID总结
    消息队列
    存储
    算法开始
    硬件杂记
    要看的
    关于kernel的疑问,不解
    杂技
  • 原文地址:https://www.cnblogs.com/codingforum/p/6208620.html
Copyright © 2020-2023  润新知