From Blush Earthworm, 1 Year ago, written in Plain Text.
  1. #!/bin/bash
  2.  
  3. myfunc(){
  4.         length="$1"
  5.         myarr="$2[@]"
  6.  
  7.         echo "length is $length"
  8.         for k in "${myarr[@]}"
  9.         do
  10.                 echo "my number is $k"
  11.         done
  12. }
  13.  
  14. i=0
  15. while (( $i < 5 ))
  16. do
  17.         arr[i]=`expr $i \* 2`
  18.         let i++
  19. done
  20.  
  21. for j in "${arr[@]}"
  22. do
  23.         echo "number is $j"
  24. done
  25.  
  26. myfunc "5" "${arr[@]}"
  27.  
  28.  
  29. The output I get:
  30.  
  31. number is 0
  32. number is 2
  33. number is 4
  34. number is 6
  35. number is 8
  36. length is 5
  37. my number is 0[@]
  38.  
captcha