shell 数组作为函数形参

时间:2021-02-13 21:29:23

问题描述:

  把字符串tarFile和数组slaves_hostIP传入函数processArray中并输出结果.

 

#!/bin/bash

function processArray() {
    tarFile=$1
    echo $tarFile
    local slaves_hostIP=(${!2})
    
    length=${#slaves_hostIP[@]}
    for((i=0;i<$length;i++));
    do
        echo ${slaves_hostIP[i]}
    done
}

slaves_hostIP=("30.72.63.94" "30.72.63.95" "30.72.63.96" "30.72.63.97")
tarFile=/tmp/lasclocker.tar

processArray $tarFile slaves_hostIP[@]