Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

How to export array in bash

123 views
Skip to first unread message

Baihao Yuan

unread,
May 13, 2003, 10:43:41 AM5/13/03
to
Hi guys,

I wonder how to export arrays in bash. I wrote code like this,
but it didn't work:

declare -ax y[100]
y[3]="thisisatest"
#start a new bash
bash
echo ${y[3]}

#string "thisisatest" expected, but nothing printed

--
Posted via Mailgate.ORG Server - http://www.Mailgate.ORG

Chris F.A. Johnson

unread,
May 13, 2003, 12:51:12 PM5/13/03
to
On Tue, 13 May 2003 at 14:43 GMT, Baihao Yuan wrote:
> Hi guys,
>
> I wonder how to export arrays in bash. I wrote code like this,
> but it didn't work:
>
> declare -ax y[100]
> y[3]="thisisatest"
> #start a new bash
> bash
> echo ${y[3]}
>
> #string "thisisatest" expected, but nothing printed

man bash:

BUGS
.....
Array variables may not (yet) be exported.


--
Chris F.A. Johnson http://cfaj.freeshell.org
===================================================================
My code (if any) in this post is copyright 2003, Chris F.A. Johnson
and may be copied under the terms of the GNU General Public License

Stephane CHAZELAS

unread,
May 13, 2003, 1:37:26 PM5/13/03
to
Chris F.A. Johnson wrote:
[...]

> man bash:
>
> BUGS
> .....
> Array variables may not (yet) be exported.
>

Well, you can use

array=(whatever foo bar)
export x_array=$(printf '%q ' "${array[@]}")

And in the child shell:

eval "array=( ${x_array[*]} )"

But why the hell would one need to do this?

--
Stéphane

0 new messages