Operating System - HP-UX
1752598 Members
4984 Online
108788 Solutions
New Discussion юеВ

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

Re: shell question on exporting arrays

see previous reply