Should VAR[n]=val cmd export VAR?
Philippe Altherr <[email protected]> Sat, 11 Jul 2026 01:06:34 +0200
| Newsgroups | gmane.comp.shells.zsh.devel |
|---|---|
| Message-ID | <CAGdYchv1GDdh8rKaARs+Lw_zRLrSRc8NTpJ+OS=f2dRwkvM87g@mail.gmail.com> |
The option ALL_EXPORT (-a) <https://zsh.sourceforge.io/Doc/Release/Options.html#index-ALL_005fEXPORT> is described as automatically exporting all parameters subsequently defined. This extends to parameters subsequently assigned, including ones with a subscript: % zsh -c 'typeset VAR=123; set -a; VAR[2]=X; set +a; typeset -p VAR; printenv VAR' export VAR=1X3 1X3 Inline assignments export the assigned parameters (with or without ALL_EXPORT option) but in that case parameters with a subscript are excluded <https://github.com/zsh-users/zsh/blob/489436767786ec8c8e16436d00ff3c7c4ce0a380/Src/exec.c#L2641> : % zsh -c 'typeset VAR=123; VAR[2]=X typeset -p VAR; VAR[2]=X printenv VAR' typeset VAR=1X3 This discrepancy looks strange to me. I expected that "VAR[n]=val cmd" would export VAR. I find the lack of export even stranger given that "VAR[n]=val" exports VAR when ALL_EXPORT is enabled. Wdyt? Could we change inline assignments to also export parameters with a subscript? Philippe