The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

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 -->
  #3 (permalink)  
Old 10-06-2008
cfajohnson's Avatar
cfajohnson cfajohnson is offline Forum Advisor  
Shell programmer, author
  
 

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

You cannot export arrays.

The easiest way to pass an array is to convert it to a scalar variable, with the elements separated by a character not used in any of the elements. For example, this uses a newline:

Code:
array_separator='
' ## adjust as needed
array=( a b c )
array_contents=$( printf "%s$array_separator" "${array[@]}" )
export array_separator array_contents
To convert it back to an array:

Code:
oIFS=$IFS
IFS=$array_separator
array=( $array_contents )
IFS=$oIFS