Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
Re: new user questions and issues
- X-seq: zsh-users 20199
- From: Kannan Varadhan <kvaradhan3@xxxxxxxxx>
- To: Bart Schaefer <schaefer@xxxxxxxxxxxxxxxx>
- Subject: Re: new user questions and issues
- Date: Mon, 11 May 2015 10:43:17 -0700
- Cc: zsh-users@xxxxxxx
- 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==
- In-reply-to: <150510220246.ZM10136@torch.brasslantern.com>
- List-help: <mailto:zsh-users-help@zsh.org>
- List-id: Zsh Users List <zsh-users.zsh.org>
- List-post: <mailto:zsh-users@zsh.org>
- Mailing-list: contact zsh-users-help@xxxxxxx; run by ezmlm
- References: <67F1153E-5D3C-4D29-BDD0-1BB9C71FF55A@gmail.com> <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@xxxxxxxxxxxxxxxx> 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
>
Messages sorted by:
Reverse Date,
Date,
Thread,
Author