The UNIX and Linux Forums  


Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google unix.com




View Single Post in the UNIX and Linux Forums - Click on the Thread or Permalink to View Entire Thread -->
  #6 (permalink)  
Old 10-14-2008
cfajohnson's Avatar
cfajohnson cfajohnson is offline Forum Advisor  
Shell programmer, author
  
 

Join Date: Mar 2007
Location: Toronto, Canada
Posts: 2,361

No shell that I know of has multidimensional arrays (but awk does).

You can use the contents of an array as an element in another array, but it will no longer be an array. You may be able to reconstruct an array from it.

For example:

a1=( 1 2 3 4 5 6 7 8 ) a2=( a b c d e f g h ) b=( "${a1[*]}" "${a2[*]}" ) printf "%s\n" "${b[@]}"
-->
Code:
a1=( 1 2 3 4 5 6 7 8 )
a2=( a b c d e f g h )
b=( "${a1[*]}" "${a2[*]}" )
printf "%s\n" "${b[@]}"
        
To reconstruct the arrays:

a1=( ${b[0]} ) a2=( ${b[1]} ) -->
Code:
a1=( ${b[0]} )
a2=( ${b[1]} )
        
If the array elements contain spaces, you will have to use a different delimiter when storing an array in the enclosing array.