Simpler Navigation coming for Servers and Operating Systems
Coming soon: a much simpler Servers and Operating Systems section of the Community. We will combine many of the older boards, and you won't have to click through so many levels to get at the information you need. If you are looking for an older board and do not find it, check the consolidated boards, as the posts are still there.
Languages and Scripting
cancel
Showing results for 
Search instead for 
Did you mean: 

shell question on exporting arrays

SOLVED
Go to solution
c_51
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
4 REPLIES
c_51
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.
Sridhar Bhaskarla
Honored Contributor
Solution

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
c_51
Trusted Contributor

Re: shell question on exporting arrays

I figured as much.

thanks
Highlighted
c_51
Trusted Contributor

Re: shell question on exporting arrays

see previous reply