execline
Software
skarnet.org
The backtick program
backtick runs a program and stores its output in an
environment variable, then executes another program.
Interface
In an execlineb script:
backtick [ -i | -I | -d | -D default ] [ -N | -n ] [ -E | -e ] variable { prog1... } prog2...
- backtick reads prog1... in a
block and unquotes it.
- It runs prog1... as a child process and saves its
output in memory. This output must not contain a null character.
- backtick execs into prog2..., with
variable added to the environment with prog1...'s
output as a value.
Options
- -N : store prog1...'s output as is, including the last newline, if any.
- -n : chomp an ending newline off prog1...'s output. This is the default.
- -e : no autoimport. This is the default.
- -E : autoimport. Instead of exec'ing into
prog2..., exec into importas -ui variable variable
prog2.... This substitutes variable into the command
line instead of putting it into the environment.
The other options tell backtick what to do if prog1...'s output
is not suitable as the contents of an environment variable (i.e. it
contains a null character) or if prog1... crashes or exits
nonzero:
- -i : backtick exits with an
approximation of prog1's exit code,
or 124 if prog1 wrote a null character. This is the default.
- -I: the value of variable is set to whatever
the start of prog1...'s output is, up to the first null character,
or to whatever prog1... wrote before crashing; chomping is applied
if required; then execution proceeds.
- -d : variable is removed from
the environment, and execution proceeds.
- -D default : the value of variable
is set to default, and execution proceeds.