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

[BUG] Can't mark unset variables as read-only



Unlike other shells, zsh mode can't mark an unset variable as read-only.
Upon encountering the readonly command, the variable is set to the empty
string instead.

Test code:

( unset -v testv && readonly testv && test "${testv+set}" = '' ) || \
        echo "*** Can't keep unset variables as read-only." 1>&2

This succeeds in ash, dash, bash, ksh, etc. but fails in zsh, even in
'emulate sh' mode.

Actual result:
testv is set to the empty string and marked read-only.

Expected result:
testv remains unset and is marked read-only.

Real-world impact:
Testing whether a variable is set is a common way of checking whether a
certain setting or feature is active. Hardened scripts may want to set
such either-set-or-unset variables as read-only after setting up their
environment, to prevent them from being accidentally clobbered. This is
not possible in zsh.



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