From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 6734 invoked by alias); 11 May 2015 17:43:36 -0000 Mailing-List: contact zsh-users-help@zsh.org; run by ezmlm Precedence: bulk X-No-Archive: yes List-Id: Zsh Users List List-Post: List-Help: X-Seq: 20199 Received: (qmail 14253 invoked from network); 11 May 2015 17:43:24 -0000 X-Spam-Checker-Version: SpamAssassin 3.3.2 (2011-06-06) on f.primenet.com.au X-Spam-Level: X-Spam-Status: No, score=-2.7 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FROM,RCVD_IN_DNSWL_LOW autolearn=ham version=3.3.2 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=content-type:mime-version:subject:from:in-reply-to:date:cc :content-transfer-encoding:message-id:references:to; bh=Ir/DL+hwTi1QRhIAID/ImAx/OMQwbeIpTrs/DTQ08lw=; b=fpY5ZfNJFq72ZWr0hBKg6vG2hlOqRlgYXQwKgw2kZZdsMmZJFgoM3yI1Ym7kxaEA5d tn0uFkGqt5CDzp/FKu3GXsK0hxWkPJ5giElBzWyIPzTAh621ml6HA+DQvOJWHTI8kRaJ g6Iozt2S5qftT3lpTE+Llsujp7MqiDOY9V1bg3g8O6NbimH8Fx+AZXDxIFJlNtT7oZH0 PW45277ZU+5jHo8Wa6+vMDeO2KS0AM0YNUB97OyeDeQCQrSl/YVNuqVnjGS2ZQupeIil z9DGW23BNWyvvsAXvTer+LM5GUMRbTQ/AXm3i/kcjzHUemmDxlrPA9ce81E31FCIWoND KD/A== X-Received: by 10.70.128.200 with SMTP id nq8mr21048295pdb.167.1431366199580; Mon, 11 May 2015 10:43:19 -0700 (PDT) Content-Type: text/plain; charset=us-ascii Mime-Version: 1.0 (Mac OS X Mail 8.2 \(2098\)) Subject: Re: new user questions and issues From: Kannan Varadhan In-Reply-To: <150510220246.ZM10136@torch.brasslantern.com> Date: Mon, 11 May 2015 10:43:17 -0700 Cc: zsh-users@zsh.org Content-Transfer-Encoding: quoted-printable Message-Id: References: <67F1153E-5D3C-4D29-BDD0-1BB9C71FF55A@gmail.com> <150510220246.ZM10136@torch.brasslantern.com> To: Bart Schaefer X-Mailer: Apple Mail (2.2098) 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 = wrote: >=20 > Most of this has been answered already, throwing one extra remark. >=20 > On May 6, 10:37am, Kannan Varadhan wrote: > } > } Issue #2. Overridden local variables get echoed? >=20 > 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".) >=20 > If you for some reason need a declaration to be local to a loop, use > an anonymous function context like this: >=20 > local _t2 > for _t2 in 0 1 2 ; do > function { > local _t3 > _t3=3DXXX__${_t2}__ > } > done >=20