linux-tutorial/codes/shell/示例脚本/脚本函数/想函数传数组数据.sh

24 lines
489 B
Bash
Raw Normal View History

2019-05-10 11:17:57 +08:00
#!/bin/bash
# trying to pass an array variable
function testit {
echo "The parameters are : $@"
#函数只会读取数组变量的第一个值
thisarray=$1
echo "The received array is ${thisarray[*]}"
local newarray
newarray=(`echo "$@"`)
echo "The new array value is : ${newarray[*]}"
}
myarray=(1 2 3 4 5)
echo "The original array is : ${myarray[*]}"
#将数组变量当成一个函数参数,函数只会去函数变量第一个值
#testit $myarray
testit ${myarray[*]}