函数传参 数组

$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
#双引号传参失败
上一篇:Linux之vim全选,全部复制,全部删除


下一篇:1082 Read Number in Chinese