From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 11033 invoked by alias); 19 Sep 2015 16:23:57 -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: 20598 Received: (qmail 26825 invoked from network); 19 Sep 2015 16:23:55 -0000 X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on f.primenet.com.au X-Spam-Level: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00 autolearn=ham autolearn_force=no version=3.4.0 X-Authority-Analysis: v=2.1 cv=X+5rdgje c=1 sm=1 tr=0 a=Qosx6O6xXGET3N4RHWVm7w==:117 a=Qosx6O6xXGET3N4RHWVm7w==:17 a=N659UExz7-8A:10 a=Y0uWUFqDxJEmtZn7S3cA:9 a=pILNOxqGKmIA:10 Message-id: <55FD8C19.4050602@eastlink.ca> Date: Sat, 19 Sep 2015 09:23:53 -0700 From: Ray Andrews User-Agent: Mozilla/5.0 (X11; Linux i686; rv:31.0) Gecko/20100101 Icedove/31.7.0 MIME-version: 1.0 To: zsh-users@zsh.org Subject: simple question regarding local variables References: <150918101506.ZM26893@torch.brasslantern.com> <55FC5BC8.4040107@eastlink.ca> <150918145300.ZM27125@torch.brasslantern.com> In-reply-to: <150918145300.ZM27125@torch.brasslantern.com> Content-type: text/plain; charset=windows-1252; format=flowed Content-transfer-encoding: 7bit I should know this: Say several functions will use the same set of variables, so you want some way of auto creating them for each function, *but* they must be local to each function. This works: 'test1' is a script: #!/usr/bin/zsh local variable=howdy local anothervariable=whatever local foo=FOO local bar=BAR local baz=BAZ # and so on ... I create all my variables in the script. 'test2' is a function that sources 'test1': test2 () { varis variable . ./test1 varis variable } ('varis' simply prints the name and the value of variables.) A run: $ test2; varis variable $variable is: "" $variable is: "howdy" $variable is: "" ... just as I want, sourcing 'test1' creates local variables in my function, but why does it work? sourcing I understand to create a child shell, thus how is it that after 'test1' returns, that it's local variables are known to 'test2'? Exactly as I want, '$variable' evaporates after 'test2' returns, so it's local. I like it, but I can't explain it.