zsh-users
 help / color / mirror / code / Atom feed
From: Kannan Varadhan <kvaradhan3@gmail.com>
To: Bart Schaefer <schaefer@brasslantern.com>
Cc: zsh-users@zsh.org
Subject: Re: new user questions and issues
Date: Mon, 11 May 2015 10:43:17 -0700	[thread overview]
Message-ID: <D71D4785-878D-47C4-832F-04ED2C9FEBCC@gmail.com> (raw)
In-Reply-To: <150510220246.ZM10136@torch.brasslantern.com>

Well, ok, that is interesting.

The reason to declare local is to be tight and explicit about variable scope.  I have been bitten with other shells in which variables are visible far outside where I would expect, leading to unexpected side effects.  The most egregious is with loop control variables for me.

What I really desire is that the variable not be inherited by or visible to any called functions.

Kannan


> On May 10, 2015, at 10:02 PM, Bart Schaefer <schaefer@brasslantern.com> wrote:
> 
> Most of this has been answered already, throwing one extra remark.
> 
> On May 6, 10:37am, Kannan Varadhan wrote:
> }
> } Issue #2.  Overridden local variables get echoed?
> 
> The tidbit that no one has explicitly mentioned is that "local" et al.
> has function scope, so it makes no sense to declare something "local"
> inside a loop body.  (In an if/else, it could make sense, as long as
> the if/else is not itself inside a loop, but the variables declared
> there will persist beyond the "fi".)
> 
> If you for some reason need a declaration to be local to a loop, use
> an anonymous function context like this:
> 
>    local _t2
>    for _t2 in 0 1 2 ; do
>      function {
>        local _t3
>        _t3=XXX__${_t2}__
>      }
>    done
> 


  reply	other threads:[~2015-05-11 17:43 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-05-06 17:37 Kannan Varadhan
2015-05-06 20:50 ` Eric Cook
2015-05-07 21:46   ` Kannan Varadhan
2015-05-07 21:54     ` ZyX
2015-05-11  5:02 ` Bart Schaefer
2015-05-11 17:43   ` Kannan Varadhan [this message]
2015-05-12  2:43     ` Bart Schaefer

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=D71D4785-878D-47C4-832F-04ED2C9FEBCC@gmail.com \
    --to=kvaradhan3@gmail.com \
    --cc=schaefer@brasslantern.com \
    --cc=zsh-users@zsh.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).