>> 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.
"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.
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
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
Received on Tue Aug 26 2014 - 07:31:06 UTC