linux-tutorial/codes/shell/示例脚本/脚本函数/想函数传数组数据.sh
2019-10-10 08:56:31 +08:00

24 lines
513 B
Bash

#!/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[*]}