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: Stan Marsh
Subject: Re: Is it possible to export a bash array variable?
Date: Mon, 05 Jan 2026 08:04:53 -0700

FYI, this seems to be the best solution to the problem:

(Import a bash assoc array into gawk)
--- Cut Here ---
gawk4 '{ getline t;foo[$0] = t } END { for (i in foo) print 
++j,i,length(foo[i]),foo[i] }' <(for i in "${!foo[@]}";do echo -e 
"$i\n${foo[$i]//$'\n'/\\\\n}";done)
1 three 14 The third item
2 Munch[This] 29 Part 2: Can you "munch" that?
3 THis index has spaces 21 And so does the value
4 You load 16 tons 20 And what do you get?
5 two 8 Number 2
6 Munch[This] and that 19 Can you munch that?
--- Cut Here ---

This seems to handle all the weird cases and is easier than parsing "declare 
-p".
Although not shown above, one of the cases in my test data had newlines in the 
data value,
and that is handled by the above code, which converts them to explicit "\n"s.  
I suppose I
should also do that for the indexes as well.

=================================================================================
Please do not send me replies to my posts on the list.
I always read the replies via the web archive, so CC'ing to me is unnecessary.

When responding to my posts, please try to refrain from giving bureaucratic 
answers.
If you have nothing useful to say, then just click Next and go on.



reply via email to

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