Re: execline: use of define, export, unexport, import

From: Patrick Mahoney <pat_at_polycrystal.org>
Date: Mon, 25 Aug 2014 22:47:21 -0500

On 2014-08-25 9:59 pm, John Vogel wrote:

> If I define a variable to some value at the top level of an execline
> script,
> there seems no way to redefine it.
>
> Stripped down example:
>
> #!/command/execlineb
> define var 0
> foreground { echo $var }
> define var 1
> foreground { echo $var }
> export var 2
> import var
> foreground { echo $var }
> unexport var
> export var 3
> import var
> echo $var
> # end of script
>
> All output is "0" from the first define. If I change the first define,
> then
> all output will be what ever I set that to.


What happens is that the arguments to the first "define" command are
"var 0 foreground ..." all the
way to the # end of script marker. The first define treats its entire
argument as a string, and
performs the substitution on every occurrence of $var, of which there
are three. It then passes
this modified set of args to the foreground command, which in turn
passes all args after its
block to export, and so on. The second define attempts to perform
substitution on its argument (the
entire set of following args), but since they've already been
substituted, there is no longer any
instance of $var, and no substitution is performed.

The trick is these are not variables as in most languages, but
substitutions performed
on a giant string of all the args from here to the end.

-- 
Patrick Mahoney <pat_at_polycrystal.org>
Received on Tue Aug 26 2014 - 03:47:21 UTC

This archive was generated by hypermail 2.3.0 : Sun May 09 2021 - 19:38:49 UTC