zoukankan      html  css  js  c++  java
  • 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
  • 相关阅读:
    JDom写入XML例子
    hdu 2549
    hdu 1328
    hdu 1334
    hdu 2547
    hdu 2374
    hdu 2550
    hdu 1335
    hdu 2548
    hdu 1722
  • 原文地址:https://www.cnblogs.com/jacson/p/4800054.html
Copyright © 2011-2022 走看看