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

From: John Vogel <>
Date: Tue, 26 Aug 2014 16:46:15 -0400

On Tue, 26 Aug 2014 08:31:06 +0100
Laurent Bercot <> wrote:

> >> If I define a variable to some value at the top level of an execline script,
> >> there seems no way to redefine it.
> Indeed, there is not.
> Patrick and Colin are correct. "var" is not a variable in the programming
> language sense; it's a key for a substitution on the command line that can
> only happen once.

This is my mistake. Your docs even clearly state this, I see it now I go back
and read some of them again.

> "import" just takes a variable in the environment and uses the name of
> that variable as a substitution key for its value - it can only happen
> once. The right way to use the same environment variable several times in
> the same script is to use different keys for different invocations, with
> the importas command.

Very clearly stated, thank you. I think I was trying to bake an apple out of
an orange. Looking back at the script, I see that I really don't need to
redefine a variable anyways. The part of it that I was trying to do that for
is overly complex and needs simplifying.

> I realize it's not very satisfying, but that's how execline substitution
> works - by rewriting the command line - and there's no easy way of doing

I don't actually find it unsatisfying. The issue is with my understanding.
As I get acclimated to writing to execline syntax, I find that I am pushing
myself harder to really understand what are the details of what is being done
by the script.

> otherwise. And I think it's only an aesthetical issue, not a technical one,
> because the only case where you cannot use importas with different keys
> is when you're performing a loop, and since loops are run in subprocesses,
> the substitution can happen once in every subprocess, and things will work
> as you expect:
> #!/command/execlineb -P
> loopwhilex
> do-something-that-sets-ARG-in-the-environment-then-execs
> import ARG unexport ARG
> echo $ARG
> do-something-* and its arguments will be run in a subprocess, and the
> substitution will be done once for every invocation of the loop, with
> the right value for $ARG.
> In the absence of loops, though, you cannot reuse keys. Please use
> an environment variable to hold the values you want to modify, and
> importas it with a unique key when you need to read the value into
> your script.
> OK, there is another way, but you really don't want to go there.
> #!/command/execlineb -P
> export VAR 1
> import VAR
> foreground { echo $VAR }
> export VAR 2
> import VAR
> foreground { echo \\$VAR }
> export VAR 3
> import VAR
> foreground { echo \\\\\\$VAR }
> export VAR 4
> import VAR
> foreground { echo \\\\\\\\\\\\\\$VAR }
> The formula for the amount of needed backslashes is left as an
> exercise for the reader.
> --
> Laurent

You are right. I think I will leave that one alone for the time being.
Thank you very much for all your help.

Received on Tue Aug 26 2014 - 20:46:15 UTC

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