easy way to cleanly dump contents of associative array in bash? -


in zsh can dump contents of associative array single command:

zsh% typeset -a foo zsh% foo=(a 1 b 2) zsh% typeset foo foo=(a 1 b 2 ) 

however despite searching high , low, best find declare -p, output contains declare -a:

bash$ typeset -a foo bash$ foo=([a]=1 [b]=2) bash$ declare -p foo declare -a foo='([a]="1" [b]="2" )' 

is there clean way obtain zsh output (ideally foo=(a 1 b 2 ) or foo='([a]="1" [b]="2" )'), preferably without resorting string manipulation?

it seems there no way other string manipulation. @ least can avoid forking sed process each time, e.g.:

dump_assoc_arrays () {     var in "$@";         read debug < <(declare -p $var)         echo "${debug#declare -a }"     done } 

Comments

Popular posts from this blog

how to insert data php javascript mysql with multiple array session 2 -

multithreading - Exception in Application constructor -

windows - CertCreateCertificateContext returns CRYPT_E_ASN1_BADTAG / 8009310b -