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

local read-only variables (Was:[PATCH] [long] typeset doesn't report tied parameters (and related issues))



2018-10-07 14:35:46 +0100, Stephane Chazelas:
[...]
> -variable.  Note that in zsh (unlike other shells) it is still possible
                                ^^^^^^^^^^^^^^^^^^^
> -to create a local variable of the same name as this is considered a
> -different variable (though this variable, too, can be marked readonly).
> -)
> +variable.
> +
> +It is still possible to change other attributes of the variable though,
> +some of which like tt(-U) or tt(-Z) would affect the value. More generally,
> +the readonly attribute should not be relied on as a security mechanism.
> +
> +Note that in zsh (like in pdksh but unlike most other shells) it is
                     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
> +still possible to create a local variable of the same name as this is
> +considered a different variable (though this variable, too, can be marked
> +readonly). Special variables that have been made readonly retain their value
> +and readonly attribute when made local.)
[...]

Actually also yash, we might as well remove that "(unlike other
shells)". Note that pdksh has quite a few derivatives (mksh,
posh, openbsd sh (I've not checked there)).

Those shells don't make a distinction for special variables.

Actually I'm not convinced it's useful to treat them
specially in that regard. For instance, if you do "readonly
IFS", you can no longer use library of functions that do some
"local IFS=:" If I add "readonly IFS" to .zshenv,
compaudit/compinit report errors and the shell exits with my
current ~/.zshrc.

See also related POSIX discussion at
http://austingroupbugs.net/view.php?id=767
http://austingroupbugs.net/view.php?id=767#c3735

-- 
Stephane



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