数组 – 如何将数组传递给bash函数
发布时间:2020-12-15 18:42:53 所属栏目:安全 来源:网络整理
导读:如何将数组传递给函数,为什么不工作? 其他问题的解决方案对我来说并不奏效. 为了记录,我不需要复制数组,所以我不介意传递引用.我想做的只是循环. $ar=(a b c)$function test() { echo ${1[@]}; }$echo ${ar[@]}a b c$test $arbash: ${1[@]}: bad substituti
如何将数组传递给函数,为什么不工作?
其他问题的解决方案对我来说并不奏效. 为了记录,我不需要复制数组,所以我不介意传递引用.我想做的只是循环. $ar=(a b c) $function test() { echo ${1[@]}; } $echo ${ar[@]} a b c $test $ar bash: ${1[@]}: bad substitution $test ${ar[@]} bash: ${1[@]}: bad substitution #!/bin/bash ar=( a b c ) test() { local ref=$1[@] echo ${!ref} } test ar (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |