#!/bin/bash
# returning an array value
function arraydblr()
{
local origarray
local newarray
local elements
local i
origarray=(`echo "[email protected]"`)
newarrray=(`echo "[email protected]"`)
elements=$[ $# -1 ]
for((i=0;i<=$elements;i++))
{
newarray[$i]=$[ ${origarray[$i]} * 2 ]
}
echo ${newarray[*]}
}
myarray=(1 2 3 4 5)
echo "The original array is ${myarray[*]}"
arg1=`echo ${myarray[*]}`
result=(`arraydblr $arg1`)
echo "The new array is : ${result[*]}"
~
shell - 函数、数组定义与调用,布布扣,bubuko.com
时间: 2024-10-11 04:20:50