bash: set array env variable and de-referencing it from any shell script fails

Read the fine manual, “bugs” section.

Array variables may not (yet) be exported.

Though, I don’t know that many consider this an actual bug. Other shells that support ksh-style arrays don’t allow exporting them either.

You may pass around array definitions rather easily, through parameters or variables or the environment. It isn’t usually very useful though.

function f {
    unset -v "$2"
    typeset "$2"
    eval "${!1}"
    typeset -p "$2"
}

typeset -a a=(a b c)
myArr=$(typeset -p a) f myArr a

Leave a Comment