Languages and Scripting
Showing results for 
Search instead for 
Do you mean 

shell question on exporting arrays

SOLVED
Go to Solution
Trusted Contributor Trusted Contributor

shell question on exporting arrays

here is the set up

set -A ab 1 2 3
export ab
typeset -x | grep ^ab

file1:
print ${ab[@]}

file2:
#!/usr/bin/ksh
print ${ab[@]}

the question is, why is the output from
the two files different

and how can I get file2's output to look like file1's
1 ACCEPTED SOLUTIONS
Honored Contributor Honored Contributor

Re: shell question on exporting arrays

Hi,

From the man page of "ksh".

//
The export built-in command does not handle arrays properly. Only the
first element of an array is exported to the environment.//

Either you have to run file2 with a . (like . ./file2) or declare your arrays within file2 or put the array in a file (say arrays.rc and call it from file2 like . /whereever/arrays.rc)

-Sri
You may be disappointed if you fail, but you are doomed if you don't try
4 REPLIES
Trusted Contributor Trusted Contributor

Re: shell question on exporting arrays

a little more information

I'm using the ksh shell for all of this and
/usr/bin/ksh ./file1 gives the same output
as file2 also.
Honored Contributor Honored Contributor

Re: shell question on exporting arrays

Hi,

From the man page of "ksh".

//
The export built-in command does not handle arrays properly. Only the
first element of an array is exported to the environment.//

Either you have to run file2 with a . (like . ./file2) or declare your arrays within file2 or put the array in a file (say arrays.rc and call it from file2 like . /whereever/arrays.rc)

-Sri
You may be disappointed if you fail, but you are doomed if you don't try
Trusted Contributor Trusted Contributor

Re: shell question on exporting arrays

I figured as much.

thanks
Highlighted
Trusted Contributor Trusted Contributor

Re: shell question on exporting arrays

see previous reply