Re: shell question on exporting arrays (132 Views)
Reply
Trusted Contributor
c_51
Posts: 60
Registered: ‎10-05-2004
Message 1 of 5 (132 Views)
Accepted Solution

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
Trusted Contributor
c_51
Posts: 60
Registered: ‎10-05-2004
Message 2 of 5 (132 Views)

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
Sridhar Bhaskarla
Posts: 6,350
Registered: ‎08-15-2001
Message 3 of 5 (132 Views)

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
c_51
Posts: 60
Registered: ‎10-05-2004
Message 4 of 5 (132 Views)

Re: shell question on exporting arrays

I figured as much.

thanks
Trusted Contributor
c_51
Posts: 60
Registered: ‎10-05-2004
Message 5 of 5 (132 Views)

Re: shell question on exporting arrays

see previous reply
The opinions expressed above are the personal opinions of the authors, not of HP. By using this site, you accept the Terms of Use and Rules of Participation.