Zsh manual mentions that option -a means ALL_EXPORT,
ALL_EXPORT (-a, ksh: -a)All parameters subsequently defined are automatically exported.
While export makes the variable available to sub-processes, the how can the same variable foo be local?
I think you might be confused on a number of fronts.
The
ALL_EXPORT (-a)setting is forsetopt, notlocal. To flag a variable for export withlocal, you uselocal -x.And you’re also confusing directions of propagation 🙂
Defining a variable as local will prevent its lifetime from extending beyond the current function (outwards or upwards depending on how your mind thinks).
This does not affect the propagation of the variable to sub-processes run within the function (inwards or downwards).
For example, consider the following scripts
qq.zsh:and
qq2.zsh:When you run
zsh qq.zsh, the output is:so you can see that neither local variable survives the return from the function. However, the auto-export of the local variables to a sub-process called within
xyzis different. The one marked for export withlocal -xis available in the sub-shell, the other isn’t.