i have currently no example i tried converting assoc 2 arr and reverses, as for examples, with content being weird filenames that tries were a week ago or so, i ended up in loops instead of parsing declare -p output sadly
but i demand extraction stuff, not just cutting away ... isnt it obvious .. i mean .. err .. ? ${var//@(abc|cde)@(bla|blubb)/\2\1} # just like sed and an extension for regex there as for example, i can give you my garbage data begin='declare -A a' end='declare -p a' per2 'a[$per]=' * declare -A a=(["\\\\"]="" ["] \$( eval echo shitt )"]="" [$'abc \034[22]="bar"']="" [$'\034']="" [$'\n']="" [2]="" ["]"]="" [" a b"]="" ["' [b"]="" ["\" ["]="" [$'\' [1]=\034']="" ["];eval echo shitt"]="" [$'foo\034 [2]="blah" ']="" [abc]="" ["abc [22]=\"bar\""]="" [blah]="" ) peace On Thu, Mar 18, 2021 at 2:33 PM Greg Wooledge <g...@wooledge.org> wrote: > On Thu, Mar 18, 2021 at 02:15:19PM +0100, Alex fxmbsw7 Ratchev wrote: > > pseudo exmaple > > Why not give a REAL example? > > > declare -A big=( mess of data ) > > var=$( declare -p big ) > > > > now to extract the elements, beware with mess of data i dont mean 'mess' > > 'of' 'data' > > You don't write bash code to parse bash syntax. You let bash do it > for you. > > Apparently you are trying to serialize an associative array and transmit > it from one instance of bash to another. That's totally fine, and > declare -p is the right tool for that. > > In the second instance of bash, to reconstruct the serialized array, > you simply eval the serialization (or source it, if it's in a file). > > In the first script: > > declare -A hash=(...) > export serialized_hash="$(declare -p hash)" > otherscript > > Then, inside otherscript: > > eval "$serialized_hash" > > Now you have an associative array named "hash", with a copy of the contents > from the first script. If you want to "extract the elements", you simply > use "${hash[key1]}" and so on. > >