From mboxrd@z Thu Jan 1 00:00:00 1970 Message-ID: <467ac3900808140547s20ea866ch97a622ac3e41f21c@mail.gmail.com> Date: Thu, 14 Aug 2008 21:47:59 +0900 From: "kazumi iwane" To: "Fans of the OS Plan 9 from Bell Labs" <9fans@9fans.net> In-Reply-To: MIME-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit Content-Disposition: inline References: <467ac3900808140420u1f971d26j25515f4bf7ddaa9e@mail.gmail.com> Subject: Re: [9fans] Local variables and rc functions Topicbox-Message-UUID: fe2262f0-ead3-11e9-9d60-3106f5b1d025 i apologize for the noise. i should have tested befoqe posting. rog, thank you for correcting me. On 8/14/08, roger peppe wrote: > 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. > >