Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

readonly, export, and local



Chet Ramey on the austin-group list:
> ksh93 does dynamic scoping if the local
> variable shadows a global variable with the export attribute set.  This
> means that it will pass the local variable value to both child functions
> and external commands, and not permit a local variable with the same name
> as a global variable with both the export and readonly attributes (in
> fact, that is a fatal error).

This has me wondering whether zsh should do something similar.  If I
have declared an exported variable as readonly, does that not imply
that I expect that value to be the one placed in the environment of
any external command that may be executed?

Yet zsh allows "local -x" to cause the local copy of a variable to go
into the environment instead, even when the variable of the same name
in the surrounding scope is marked readonly.

Certainly either semantics could be argued.  Zsh's current behavior
provides a slightly better illusion of lexical scope.



Messages sorted by: Reverse Date, Date, Thread, Author