shell script数组使用函数输出

#!/bin/bash
#  array variable to function test

function testit {
  local newarray
  newarray=("$@")
  echo "The new array value is: ${newarray[*]}"
}

myarray=(1 2 3 4 5)
echo "The original array is ${myarray[*]}"
testit ${myarray[*]}

注意:

 function testit { 中函数名 testit 和 { 中间是必须加上空格的。

 myarray=(1 2 3 4 5) 中的 (1 2 3 4 5) 两边不能加上双引号,等号两边不能加上空格的。

运行 sh test.sh 输出为:

The original array is 1 2 3 4 5
The new array value is: 1 2 3 4 5

 

posted @ 2015-09-11 09:56  todaytoday  阅读(349)  评论(0编辑  收藏  举报