#!/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

 

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-11-21
  • 2022-02-17
  • 2022-12-23
  • 2021-07-12
猜你喜欢
  • 2022-02-13
  • 2022-02-20
  • 2021-12-25
  • 2021-09-15
  • 2021-04-06
  • 2022-12-23
  • 2021-08-10
相关资源
相似解决方案