Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
[BUG] Can't mark unset variables as read-only
- X-seq: zsh-workers 34990
- From: Martijn Dekker <martijn@xxxxxxxx>
- To: zsh-workers@xxxxxxx
- Subject: [BUG] Can't mark unset variables as read-only
- Date: Wed, 29 Apr 2015 07:48:35 +0200
- List-help: <mailto:zsh-workers-help@zsh.org>
- List-id: Zsh Workers List <zsh-workers.zsh.org>
- List-post: <mailto:zsh-workers@zsh.org>
- Mailing-list: contact zsh-workers-help@xxxxxxx; run by ezmlm
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