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 default ] [ -n ] 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 : chomp an ending newline off prog1...'s
output.
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 1.
- -I : variable is removed from
the environment, and execution proceeds.
- -D default : the value of variable
is set to default, and execution proceeds.
- neither of those options: 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;
then execution proceeds.
Notes
- You can start prog2... with "import -u variable"
to perform variable substitution.