zsh-workers
 help / color / mirror / code / Atom feed
* typeset -U within a function
@ 2001-11-10  2:29 Vin Shelton
  2001-11-10  7:21 ` Borsenkow Andrej
  0 siblings, 1 reply; 3+ messages in thread
From: Vin Shelton @ 2001-11-10  2:29 UTC (permalink / raw)
  To: zsh-workers

>From either zsh-4.0.4 or from the latest CVS sources, when I create a
function like this:

function bar {
  typeset -U PATH
  PATH=/xxx:/yyy
}

and then run it, PATH is unchanged:

  zion% /usr/local/zsh-4.0.4/bin/zsh -f
  zion% function bar {
  function> typeset -U PATH
  function> PATH=/xxx:/yyy
  function> }
  zion% echo $PATH
  /home/acs/bin:/usr/local/bin:/usr/X11R6/bin:/bin:/usr/bin:/etc
  zion% bar
  zion% echo $PATH
  /home/acs/bin:/usr/local/bin:/usr/X11R6/bin:/bin:/usr/bin:/etc

If I remove the 'typeset -U PATH' line (even if PATH already had been
'typeset -U' before entering the function), the value of PATH is
changed by the function bar:

  zion% function bar {
  function> PATH=/xxx:/yyy
  function> }
  zion% echo $PATH
  /home/acs/bin:/usr/local/bin:/usr/X11R6/bin:/bin:/usr/bin:/etc
  zion% bar
  zion% echo $PATH
  /xxx:/yyy


  - vin


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

* Re: typeset -U within a function
  2001-11-10  2:29 typeset -U within a function Vin Shelton
@ 2001-11-10  7:21 ` Borsenkow Andrej
  2001-11-10 14:13   ` Vin Shelton
  0 siblings, 1 reply; 3+ messages in thread
From: Borsenkow Andrej @ 2001-11-10  7:21 UTC (permalink / raw)
  To: Vin Shelton; +Cc: zsh-workers

Vin Shelton wrote:

> From either zsh-4.0.4 or from the latest CVS sources, when I create a
> function like this:
> 
> function bar {
>   typeset -U PATH
>   PATH=/xxx:/yyy
> }
> 
> and then run it, PATH is unchanged:
> 


typeset -Ug PATH

typeset -U creates local variable.

-andrej


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

* Re: typeset -U within a function
  2001-11-10  7:21 ` Borsenkow Andrej
@ 2001-11-10 14:13   ` Vin Shelton
  0 siblings, 0 replies; 3+ messages in thread
From: Vin Shelton @ 2001-11-10 14:13 UTC (permalink / raw)
  To: Borsenkow Andrej; +Cc: zsh-workers

Borsenkow Andrej <Andrej.Borsenkow@mow.siemens.ru> writes:
> Vin Shelton wrote:
> 
> > From either zsh-4.0.4 or from the latest CVS sources, when I create a
> > function like this:
> > function bar {
> 
> >   typeset -U PATH
> >   PATH=/xxx:/yyy
> > }
> > and then run it, PATH is unchanged:
> 
> >
> 
> 
> 
> typeset -Ug PATH
> 
> typeset -U creates local variable.
> 
> -andrej

Ahh - I see.  Here's what the zshbuiltins man page has to say:

    A parameter is created for each name that does not already refer
    to one.  When inside a function, a new parameter is created for
    every name (even those that already exist), and is unset again
    when the function completes.  See `Local Parameters' in
    zshparam(1).  The same rules apply to special shell parameters,
    which retain their special attributes when made local.

Thanks, Andrej.

  - vin


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

end of thread, other threads:[~2001-11-10 14:11 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2001-11-10  2:29 typeset -U within a function Vin Shelton
2001-11-10  7:21 ` Borsenkow Andrej
2001-11-10 14:13   ` Vin Shelton

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