为实现函数返回数组到脚本 给出如下代码:
#vim test0
#!/bin/bash
#return an array value
function arraybkfunc {
local origarr27
local newarr27
local elements27
local i
origarr27=('echo "$@"')
newarr27=('echo "$@"')
elements27=$[ $# - 1 ]
for ((i=0 ; i<=$elements27 ; i++))
{
newarr27[$i]=$[ ${origarr27[$i]} * 2 ] //本句出错,大意对整个、数组乘2 而非对每一个元素
}
# echo "the new array: ${newarr27[*]}"
echo ${newarr27[*]}
echo "test for this \function"
}
myarray=(1 2 3 4 5)
echo "the original array :${myarray[*]}"
arg1='echo ${myarray[*]}'
# result=('arraybkfunc $arg1')
arraybkfunc $arg1
echo "the new array : ${result[*]}"
阅读(568) | 评论(0) | 转发(0) |