其他分享
首页 > 其他分享> > 函数传参 数组

函数传参 数组

作者:互联网

$cat gg.sh
#! /bin/bash

exit=([0]="apple orange" [1]="pear")
relay=([0]="apple orange" [1]="pear")


function gg() {
tmp=$1
echo ${tmp[0]}
echo ${tmp[1]}
tmp=$2
echo ${tmp[0]}
echo ${tmp[1]}

for i in ${tmp[*]}; do
echo $i
done
}

gg "${exit[*]}" "${relay[*]}"

$./gg.sh 
$apple orange pear
$
$apple orange pear
$
$apple
$orange
$pear
#双引号传参失败

标签:传参,tmp,函数,pear,echo,gg,数组,orange,apple
来源: https://www.cnblogs.com/toughcactus/p/15007839.html