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

From: John Vogel <jvogel4_at_stny.rr.com>
Date: Tue, 26 Aug 2014 16:22:24 -0400

On Mon, 25 Aug 2014 22:04:47 -0700
Colin Booth <cathexis_at_gmail.com> wrote:

>
> Define is weird (I've just been playing around with it recently, so someone
> should correct me if I'm wrong, please). As Patrick said, define overwrites
> all instances of a key with a value. So in the case of youre script you've
> overwritten var with 0 everywhere you go.
>
> For example the following script displays 0 then 1 then 0 again:
> #!/command/execlineb
> define var "0"
> foreground { echo $var }
> define 0 "1"
> foreground { echo $0 }
> echo $var
>

> (un)export is for setting and unsetting environment variables, not injecting
> variables into your script. Once you've exported a variable into the environment
> you should import it to be used:
>
> #!/command/execlineb
> emptyenv
> export var "some text"
> foreground { env }
> foreground { echo $var }
> import var
> echo $var
>
> Note that import appears to have the same no-clobber powers as define though
> export doesn't:
> #!/command/execlineb
> emptyenv
> export var "some text"
> export var "other text"
> import var
> echo $var
>
> outputs "other text" whereas:
>
> #!/command/execlineb
> emptyenv
> export var "some text"
> import var
> export var "other text"
> import var
> echo $var
>
> outputs "some text"
>
> Presumably this is similar to the define issue above. I can't find a good way
> to override the imported variable by name. The closest I've found is to use
> `importas var2 var ; echo $var2' to pull in the (current) value of var
> to the local variable
> var2, and then echo that.
>

> Cheers!

On top of Patrick's explanation, this solidifies my understanding of substitution
and the interaction with export/import of env variables. Thank you very much.

--
  John
Received on Tue Aug 26 2014 - 20:22:24 UTC

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