From: Martijn Dekker <martijn@inlv.org>
To: zsh-workers@zsh.org
Subject: [BUG] Can't mark unset variables as read-only
Date: Wed, 29 Apr 2015 07:48:35 +0200 [thread overview]
Message-ID: <554070B3.5020204@inlv.org> (raw)
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.
next reply other threads:[~2015-04-29 6:14 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-04-29 5:48 Martijn Dekker [this message]
2015-04-29 6:35 Martijn Dekker
2015-04-29 10:36 ` Peter Stephenson
2015-04-29 10:57 ` Mikael Magnusson
2015-04-29 11:01 ` Mikael Magnusson
2015-04-29 13:46 ` Martijn Dekker
2015-04-29 13:55 ` Bart Schaefer
2015-04-29 14:41 ` Peter Stephenson
2015-04-29 15:33 ` Chet Ramey
2015-04-29 19:09 ` Stephane Chazelas
2015-04-29 23:22 ` Chet Ramey
2015-04-30 3:57 ` Bart Schaefer
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=554070B3.5020204@inlv.org \
--to=martijn@inlv.org \
--cc=zsh-workers@zsh.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this public inbox
https://git.vuxu.org/mirror/zsh/
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).