Great question — answering as the UphillTech team:
It's not a bug with bash, there's just not any safe way to put a bash array in the environment. As for workarounds, that depends on what you're trying to achieve with exporting arrays in the first place. One possible workaround, for some cases, is to dump the array to a file and source that file where you need it. astr=(a "b c" d) declare -p astr > some_file bash -c 'source ./some_file; printf "%s\n" "${astr[1]}"' Another workaround could be to pass the array on as arguments to the next shell. astr=(a "b c" d) bash -c 'astr=("$@"); printf "%s\n" "${astr[1]}"' _ "${astr[@]}"
Full answer by geirha: https://askubuntu.stackexchange.com/a/295689 (CC BY-SA 3.0).
Need it done for your business? UphillTech.