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

Re: Unsetting a variable that was not previously set [kind of update]



Michael Prokop wrote:
> I found the thread "Unsetting a variable that was not previously
> set" -> http://www.zsh.org/mla/users/2003/msg00312.html in the
> zsh-ml-archive.

Yes, we didn't really reach a conclusion.

It looks like returning status 0 in this case is fairly standard
behaviour, so we probably ought to change it for future versions.
(This is on the basis that the next version is probably going to be
4.3.)

Index: README
===================================================================
RCS file: /cvsroot/zsh/zsh/README,v
retrieving revision 1.21
diff -u -r1.21 README
--- README	14 Jan 2005 13:04:49 -0000	1.21
+++ README	9 Mar 2005 17:03:38 -0000
@@ -24,78 +24,12 @@
 Possible incompatibilities
 ---------------------------
 
-Currently the only known incompatibilities between 4.2.0 and later
-versions are minor:
+Since 4.2:
 
-
-Since 4.2.1:
-
-The "test" and "[" builtins now behave more like relevant Unix standards
-suggest they should.  Previously they were a simple front-end to the same
-tests used by zsh's "[[" syntax.  (The documentation was previously cagey
-about what "test" and "[" actually did.)  "[[" has always been the
-recommended way of implementing tests within zsh.
-
-In recent versions of zsh, typing the end-of-file (EOF) character
-(typically ^D, although this can be altered with the "stty" command)
-repeatedly in the line editor printed a warning message, but never exited the
-shell.  This was a departure from the traditional behaviour of zsh and
-other shells where the shell would exit after 10 EOFs.  The traditional
-behaviour has been restored.  Also, binding a user-defined editor command
-to the EOF character now suppresses the EOF behaviour inside the line
-editor; it is possible to emulate it if desired.
-
-
-From 4.2.0 to 4.2.1:
-
-IPv6 addresses must be specified in square brackets in the zftp module and
-the function system built on top of the zftp module.
-
-Special traps for pseudosignals ZERR, DEBUG and EXIT are no longer executed
-inside other traps.  Users may well have assumed this was the case anyway
-since the behaviour was not explicity documented.  See the NEWS file for
-more detail.
-
-By default, a maximum function depth of 4096 is now compiled into the
-shell.  This may be altered during configuration; see `Function depth' in
-INSTALL.
-
-
-Some particular differences you may notice between the 4.0 and 4.2 series
-of releases:
-
-The bash-compatibility zle functions described in the zshcontrib manual
-page have been removed as a more configurable set of editing widgets for
-dealing with words have been added.  The following code in .zshrc will set
-up for bash-style word handling:
-  autoload -U select-word-style
-  select-word-style bash
-
-The `=prog' facility for expanding command paths (provided the EQUALS
-option is enabled, as it is by default) no longer expands aliases.  It was
-felt this feature was underused and confusing.
-
-In 4.0, a literal `/' was quoted in the `src' text of a substitution of the
-form `${foo/src/rep}' or ${foo//src/rep} with two backslashes.  This was
-documented, but inconsistent with normal quoting conventions and poorly
-implemented.  The `/' now requires only one backslash to quote it whether
-or not the expression occurs in double quotes.  For example:
-  % foo=word/bird
-  % print ${foo/\//-} "${foo/\//+}"
-  word-bird word+bird
-Note also the following workaround which is valid in all versions of the
-shell that support this syntax:
-  % slash=/
-  % foo=word/bird
-  % print ${foo/$slash/-} "${foo/$slash/+}"
-
-In 4.0, the -M option to bindkey used the first non-option argument to
-specify the keymap, whereas it now uses an argument to the option.  Hence:
-  bindkey -M -R keymap a-z self-insert
-needs to be rewritten as
-  bindkey -M keymap -R a-z self-insert
-The following form works in both versions:
-  bindkey -R -M keymap a-z self-insert
+The "unset" builtin now does not regard the unsetting of non-existent
+variables as an error, so can still return status 0 (depending on the
+handling of other arguments).  This appears to be the standard shell
+behaviour.
 
 Documentation
 -------------
Index: Src/builtin.c
===================================================================
RCS file: /cvsroot/zsh/zsh/Src/builtin.c,v
retrieving revision 1.135
diff -u -r1.135 builtin.c
--- Src/builtin.c	6 Feb 2005 20:36:41 -0000	1.135
+++ Src/builtin.c	9 Mar 2005 17:03:40 -0000
@@ -2726,8 +2726,12 @@
 	pm = (Param) (paramtab == realparamtab ?
 		      gethashnode2(paramtab, s) :
 		      paramtab->getnode(paramtab, s));
+	/*
+	 * Unsetting an unset variable is not an error.
+	 * This appears to be reasonably standard behaviour.
+	 */
 	if (!pm)
-	    returnval = 1;
+	    continue;
 	else if ((pm->flags & PM_RESTRICTED) && isset(RESTRICTED)) {
 	    zerrnam(name, "%s: restricted", pm->nam, 0);
 	    returnval = 1;

-- 
Peter Stephenson <pws@xxxxxxx>                  Software Engineer
CSR PLC, Churchill House, Cambridge Business Park, Cowley Road
Cambridge, CB4 0WZ, UK                          Tel: +44 (0)1223 692070


**********************************************************************
This email and any files transmitted with it are confidential and
intended solely for the use of the individual or entity to whom they
are addressed. If you have received this email in error please notify
the system manager.

**********************************************************************



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