函数传参 数组

时间:2021-07-13 20:25:19   收藏:0   阅读:15

$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
#双引号传参失败

原文:https://www.cnblogs.com/toughcactus/p/15007839.html

评论(0
© 2014 bubuko.com 版权所有 - 联系我们:wmxa8@hotmail.com
打开技术之扣,分享程序人生!