From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 9549 invoked from network); 2 Nov 1997 17:07:54 -0000 Received: from math.gatech.edu (list@130.207.146.50) by ns1.primenet.com.au with SMTP; 2 Nov 1997 17:07:54 -0000 Received: (from list@localhost) by math.gatech.edu (8.8.5/8.8.5) id LAA12024; Sun, 2 Nov 1997 11:48:52 -0500 (EST) Resent-Date: Sun, 2 Nov 1997 11:48:52 -0500 (EST) Sender: stringfe@rmcs.cranfield.ac.uk Message-Id: <345CAEFA.EE@rmcs.cran.ac.uk> Date: Sun, 02 Nov 1997 16:48:58 +0000 From: "stringfellow.n.d" X-Mailer: Mozilla 3.02 (X11; I; SunOS 5.5.1 sun4u) Mime-Version: 1.0 To: ramos@ih4ess.ih.lucent.com Cc: zsh-workers@math.gatech.edu Subject: Re: leftover debugging statements? References: <199711012201.QAA13863@ihnns581.ih.lucent.com> Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit Resent-Message-ID: <"sfYHs1.0.mx2.pxANq"@math> Resent-From: zsh-workers@math.gatech.edu X-Mailing-List: archive/latest/3594 X-Loop: zsh-workers@math.gatech.edu Precedence: list Resent-Sender: zsh-workers-request@math.gatech.edu ramos@ih4ess.ih.lucent.com wrote: > > hello, > > Did somebody leave some leftover debugging statements in > zsh 3.0.5? > > Some assignments to a local (typeset) variable cause > some garbage to be printed out. > > Example script & output (sorry I don't have time to > isolate this any further... I hope this is enough to > jog someone's memory): > > PS1='zsh> ' > > zsh> which bug > bug () { > typeset fred > fred=NULL > typeset sourcefile > echo 'Start loop...' > for sourcefile in $* > do > typeset bar > if [[ $fred = NULL ]] > then > typeset foo > foo=(`echo output from some process`) > bar=$foo[0] > else > bar=$fred > fi > done > echo 'End loop...' > return 0 > } ... Using zsh 3.1.2b I get the following: zsh> bug X Y Z Start loop... bar=output bar=output End loop... where the system is: zsh> uname -a SunOS voltera 5.5.1 Generic sun4u sparc SUNW,Ultra-1 The 'bar=output' lines occur when the 'typeset bar' line is executed, because the previously declared bar is still in scope. Therefore 'typeset bar' has the same effect as typing 'typeset PATH' at the prompt, i.e. it returns the current value of the variable rather than declaring a fresh variable. The scoping rules for typeset in the Z Shell Guide only mention variables being local to a function (unless I've missed something), so that I would expect to get the same output as below > zsh> bug X Y Z > Start loop... > bar=output > foo=(output from some process) > bar=output > foo=(output from some process) > End loop... > Either moving the typeset statements out of the loop or inserting explicit unset statements removes the extraneous output. N.B. On my system, using the original bug program leads to the variable foo being persistant. It may be overwritten with 'foo=...' but any attempt to unset foo (even after it has been overwritten) resets foo to the value 'output from some process'.