help-bash
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Is it possible to export a bash array variable?


From: Chet Ramey
Subject: Re: Is it possible to export a bash array variable?
Date: Mon, 5 Jan 2026 10:48:43 -0500
User-agent: Mozilla Thunderbird

On 1/3/26 3:59 PM, Stan Marsh wrote:


I found this in variables.c:

--- Cut Here ---
#if ARRAY_EXPORT
#define BASHARRAY_PREFIX        "BASH_ARRAY_"
#define BASHARRAY_PREFLEN       11
#define BASHARRAY_SUFFIX        "%%"
#define BASHARRAY_SUFFLEN       2

#define BASHASSOC_PREFIX        "BASH_ASSOC_"
#define BASHASSOC_PREFLEN       11
#define BASHASSOC_SUFFIX        "%%"    /* needs to be the same as 
BASHARRAY_SUFFIX */
#define BASHASSOC_SUFFLEN       2
#endif
--- Cut Here ---

Which makes it sound like it would work for assoc arrays as well as
indexed.  Is that true?

Yes.


Also, what exactly do you get in the exported variable?  Is it pretty
much the same as what you get from "declare -p array" ? (*)

No. The value is the same, but the name is mangled in the same way as
exported functions, to avoid collisions between exported arrays and
exported variables that happen to have the same form.

Finally, note that my use case is I'd like an easy way to get the
contents of an assoc array into an external program (GAWK).  I've
developed a couple of kludgey ways to do it (**), but would like something
better.

This is not that. It's only intended to work between bash instances.

--
``The lyf so short, the craft so long to lerne.'' - Chaucer
                 ``Ars longa, vita brevis'' - Hippocrates
Chet Ramey, UTech, CWRU    chet@case.edu    http://tiswww.cwru.edu/~chet/

Attachment: OpenPGP_signature.asc
Description: OpenPGP digital signature


reply via email to

[Prev in Thread] Current Thread [Next in Thread]