zoukankan      html  css  js  c++  java
  • Shell脚本(四)数组

    平时写脚本还没有用到过数组,暂时先记录下用法。

    #!/bin/bash
    
    array1=(1 2 3 4 5)
    
    array1_length=${#array1[@]}
    echo "array1 length: ${array1_length}"
    
    for item in ${array1[@]}
    do
        echo "current item of array1: ${item}"
    done
    
    array2[0]="test0"
    array2[1]="test1"
    array2[2]="test2"
    array2[3]="test3"
    
    for((i=0; i < ${#array2[@]}; i++))
    do
        echo "current_index: $i, current_value: ${array2[$i]}"
    done
    
    # 关联数组
    declare -A dictArray
    dictArray=([key3]=value3 [key1]=value1 [key2]=value2)
    
    dictArray_length=${#dictArray[@]}
    echo "dictArray length: ${dictArray_length}"
    
    for key in ${!dictArray[@]}
    do
        echo "current key of dictArray: ${key}"
    done
    
    for value in ${dictArray[@]}
    do
        echo "current value of dictArray: ${value}"
    done
    
    for key in ${!dictArray[@]}
    do
        echo "key: ${key}, value: ${dictArray[${key}]}"
    done
  • 相关阅读:
    富文本编辑器编辑
    你是怎么发上去的
    f
    xxx
    test
    sgsdg
    code
    html2canvas.js——HTML转Canvas工具
    后台返回流图片的处理方式。(原生,JQ,VUE)
    渐进式web应用开发---service worker
  • 原文地址:https://www.cnblogs.com/gattaca/p/7251690.html
Copyright © 2011-2022 走看看