From mboxrd@z Thu Jan 1 00:00:00 1970 Message-ID: Date: Thu, 14 Aug 2008 13:14:36 +0100 From: "roger peppe" To: "Fans of the OS Plan 9 from Bell Labs" <9fans@9fans.net> In-Reply-To: <467ac3900808140420u1f971d26j25515f4bf7ddaa9e@mail.gmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit Content-Disposition: inline References: <467ac3900808140420u1f971d26j25515f4bf7ddaa9e@mail.gmail.com> Subject: Re: [9fans] Local variables and rc functions Topicbox-Message-UUID: fe1e7db6-ead3-11e9-9d60-3106f5b1d025 On Thu, Aug 14, 2008 at 12:20 PM, kazumi iwane wrote: > if you want to delay the expansion of an env var until fn invocation,,use eval. > > % fn foo {eval echo $$bar} sorry, but that's so, so wrong. 1) $$bar gives the value of the variable named by the contents of the variable bar, so that the above, given that $bar contains 'baz' will echo $baz. 2) $$bar above is evaluated _before_ eval is invoked, so the line is not very different from {echo $$bar}, except that if $$bar holds any syntax characters they'll get interpreted by the shell. it's almost never necessary to use eval with rc. 3) expansion of env. vars *is* delayed until fn invocation. e.g. % fn foo {echo $bar} % bar = baz % foo baz % it just seems as if the local variable assignment isn't propagated into the fn context. i don't have time to look into it now (i really shouldn't be spending time writing this email, but i couldn't resist the bait). rog.