zsh-workers
 help / color / mirror / code / Atom feed
* Bug/Caveat for local variables in functions
@ 2002-12-31  1:54 tim_smithers
  2002-12-31  4:02 ` Bart Schaefer
  0 siblings, 1 reply; 2+ messages in thread
From: tim_smithers @ 2002-12-31  1:54 UTC (permalink / raw)
  To: zsh-workers


Hi,
     This is either a bug, or something which maybe should be noted as not
able to be done in the man page.

You can't create a local variable with the same name as a special var.

Eg:

testit()
{
    local path=foo
    echo $path
}

this echo's your path, not 'foo'. You don't get any warnings about the
assignment not working etc.

The main reason I found it was porting some shell which works in ksh and
bash to zsh compliant (which has a "path" variable).

Regards,
     - Tim




The information contained in this e-mail communication may be confidential.
You should only read, disclose, re-transmit,copy, distribute, act in
reliance on or commercialise the information if you are authorised to do
so. If you are not the intended recipient of this e-mail communication,
please immediately notify us by e-mail to postmaster@mlc.com.au, or reply
by e-mail direct to the sender and then destroy any electronic and paper
copy of this message.

Any views expressed in this e-mail communication are those of the
individual sender, except where the sender specifically states them to be
the views of a member of the National Australia Bank Group of companies.

The National Australia Bank Group of companies does not represent, warrant
or guarantee that the integrity of this communication has been maintained
nor that the communication is free of errors, virus or interference.


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

* Re: Bug/Caveat for local variables in functions
  2002-12-31  1:54 Bug/Caveat for local variables in functions tim_smithers
@ 2002-12-31  4:02 ` Bart Schaefer
  0 siblings, 0 replies; 2+ messages in thread
From: Bart Schaefer @ 2002-12-31  4:02 UTC (permalink / raw)
  To: zsh-workers

On Dec 31, 12:54pm, tim_smithers@mlc.com.au wrote:
}
} You can't create a local variable with the same name as a special var.

Yes, you can.  Yout just have to tell zsh to make the local non-special.

    testit()
    {
	local -h path=foo
	echo $path
    }


} testit()
} {
}     local path=foo
}     echo $path
} }
} 
} this echo's your path, not 'foo'. You don't get any warnings about the
} assignment not working etc.

What version of zsh do you have?  Without the -h option, I get this:

testit:local:2: path: can't assign initial value for array

} The main reason I found it was porting some shell which works in ksh and
} bash to zsh compliant (which has a "path" variable).

Usually the quickest way to do this is just to place

    emulate -L sh

at the top of the script.  If you're really _porting_ to native zsh mode,
rather than wanting to have zsh execute a Bourne shell script, then you
may have a lot more changes to make than just adding -h to locals.  For
example, you're probably also going to have to change variable references
from $VAR to $=VAR (when not quoted), to get sh-style word splitting.

-- 
Bart Schaefer                                 Brass Lantern Enterprises
http://www.well.com/user/barts              http://www.brasslantern.com

Zsh: http://www.zsh.org | PHPerl Project: http://phperl.sourceforge.net   


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

end of thread, other threads:[~2002-12-31  4:03 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2002-12-31  1:54 Bug/Caveat for local variables in functions tim_smithers
2002-12-31  4:02 ` 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).