summaryrefslogtreecommitdiff
path: root/doc/backtick.html
blob: 38c02a2afb2f3542093a9281125accfdb1dd6e09 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
<html>
  <head>
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
 <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
 <meta http-equiv="Content-Language" content="en" />
 <title>execline: the backtick command</title>
 <meta name="Description" content="execline: the backtick command" />
 <meta name="Keywords" content="execline command backtick" />
 <!-- <link rel="stylesheet" type="text/css" href="//skarnet.org/default.css" /> -->
</head>
<body>

<p>
<a href="index.html">execline</a><br />
<a href="//skarnet.org/software/">Software</a><br />
<a href="//skarnet.org/">skarnet.org</a>
</p>

<h1> The <tt>backtick</tt> program </h1>

<p>
<tt>backtick</tt> runs a program and stores its output in an
environment variable, then executes another program.
</p>

<h2> Interface </h2>

<p>
 In an <a href="execlineb.html">execlineb</a> script:
</p>

<pre>
     backtick [ -i | -I | -x | -D <em>default</em> ] [ -N | -n ] [ -E | -e ] <em>variable</em> { <em>prog1...</em> } <em>prog2...</em>
</pre>

<ul>
 <li> <tt>backtick</tt> reads <em>prog1...</em> in a
<a href="el_semicolon.html">block</a> and unquotes it. </li>
 <li> It runs <em>prog1...</em> as a child process and saves its
output in memory. This output must not contain a null character. </li>
 <li><tt>backtick</tt> execs into <em>prog2...</em>, with
<em>variable</em> added to the environment with <em>prog1...</em>'s
output as a value. </li>
</ul>

<h2> Options </h2>

<ul>
 <li> <tt>-N</tt>&nbsp;: store <em>prog1...</em>'s output as is, including the last newline, if any. </li>
 <li> <tt>-n</tt>&nbsp;: chomp an ending newline off <em>prog1...</em>'s output. This is the default. </li>
 <li> <tt>-e</tt>&nbsp;: no autoimport. This is the default. </li>
 <li> <tt>-E</tt>&nbsp;: autoimport. Before exec'ing into
<em>prog2...</em>, perform a
<a href="https://skarnet.org/software/execline/el_substitute.html">substitution</a>
so that <tt>$?</tt> is replaced with <em>prog1...</em>'s exitcode (if
applicable, see below), and
<tt>${<em>variable</em>}</tt> is replaced with <em>prog1...</em>'s output,
instead of keeping the results in the environment. The variables will not
appear in the environment; if they preexisted in <tt>backtick</tt>'s
environment, they will be removed. </li>
</ul>

<p>
 The other options tell backtick what to do if <em>prog1...</em>'s output
is not suitable as the contents of an environment variable (i.e. it
contains a null character) or if <em>prog1...</em> crashes or exits
nonzero:
</p>

<ul>
 <li> <tt>-i</tt>&nbsp;: backtick exits with an
<a href="exitcodes.html">approximation</a> of <em>prog1</em>'s exit code,
or 124 if <em>prog1</em> wrote a null character. This is the default. </li>
 <li> <tt>-I</tt>: the value of <em>variable</em> is set to whatever
the start of <em>prog1...</em>'s output is, up to the first null character,
or to whatever <em>prog1...</em> wrote before crashing; chomping is applied
if required; then execution proceeds. </li>
 <li> <tt>-x</tt>&nbsp;: <em>variable</em> is <strong>removed</strong> from
the environment, and execution proceeds. </li>
 <li> <tt>-D&nbsp;<em>default</em></tt>&nbsp;: the value of <em>variable</em>
is set to <em>default</em>, and execution proceeds. </li>
</ul>

<p>
 If the command line can keep running after <em>prog1</em> crashes or exits
nonzero, i.e. if one of the <tt>-I</tt>, <tt>-x</tt> -or <tt>-D</tt> has been
given, then <tt>backtick</tt> also adds the <tt>?</tt> variable to the
environment; it then contains an <a href="exitcodes.html">approximation</a>
of <em>prog1</em>'s exit code.
</p>

</body>
</html>