zsh-workers
 help / color / mirror / code / Atom feed
* [BUG] Can't mark unset variables as read-only
@ 2015-04-29  5:48 Martijn Dekker
  0 siblings, 0 replies; 12+ messages in thread
From: Martijn Dekker @ 2015-04-29  5:48 UTC (permalink / raw)
  To: zsh-workers

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.


^ permalink raw reply	[flat|nested] 12+ messages in thread
* [BUG] Can't mark unset variables as read-only
@ 2015-04-29  6:35 Martijn Dekker
  2015-04-29 10:36 ` Peter Stephenson
  0 siblings, 1 reply; 12+ messages in thread
From: Martijn Dekker @ 2015-04-29  6:35 UTC (permalink / raw)
  To: zsh-workers

Unlike other shells, zsh 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.


^ permalink raw reply	[flat|nested] 12+ messages in thread

end of thread, other threads:[~2015-04-30  3:57 UTC | newest]

Thread overview: 12+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-04-29  5:48 [BUG] Can't mark unset variables as read-only Martijn Dekker
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

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).