execline
Software
www.skarnet.org
The multisubstitute program
multisubstitute performs several substitutions at once in
its argv, then executes another program.
Interface
In an execlineb script:
multisubstitute [ -P sharp ]
{
[ define [ -s [ -c ] [ -d delim ] ] variable value ]
[ importas [ -s [ -c ] [ -d delim ] ] variable envvar ]
[ import [ -s [ -c ] [ -d delim ] ] envvar ]
[ backtick [ -n ] [ -s [ -c ] [ -d delim ] ] variable { command... } ]
[ elglob [ -v ] [ -w ] [ -s ] [ -m ] [ -e ] [ -0 ] variable pattern ]
...
}
prog...
- multisubstitute reads a block
containing a series of substitution commands. It performs all
those substitutions on
prog... in parallel. Check the relevant documentation page
to learn about the syntax of each substitution command.
- multisubstitute then execs into the modified prog....
Options
- -P sharp : positional parameters. If this option is given,
multisubstitute will read the script's positional parameters and
substitute them along with the other variables, as if the
elgetpositionals command was run at
the same time with the -P sharp option.
Rationale
Security
multisubstitute can be used to avoid unwanted
serial substitutions. Consider the following script:
#!/command/execlineb
export A wrong
define B ${A}
import A
echo ${B}
Running it will print wrong, because A is substituted
after B. On the contrary, the following script:
#!/command/execlineb
export A wrong
multisubstitute
{
define B ${A}
import A
}
echo ${B}
will print ${A}, because A and B are substituted at the same
time. Serial substitution may be what you want - but when in doubt,
always perform parallel substitution.
Efficiency
Substitution is a costly mechanism:
the whole argv is read three times and rewritten twice.
Serial substitution multiplies the cost by the number of
substitutions, whereas parallel substitution pays the price only once.
Credits
Paul Jarc first originated the
idea of the multisubstitute command and a possible syntax.