summaryrefslogtreecommitdiff
path: root/doc/forbacktickx.html
blob: c9e2c4eab9037c9bd6c6cfa033f3cfdde9f65e18 (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
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
<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 forbacktickx command</title>
  <meta name="Description" content="execline: the forbacktickx command" />
  <meta name="Keywords" content="execline command forbacktickx" />
  <!-- <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>forbacktickx</tt> program </h1>

<p>
<tt>forbacktickx</tt> runs a program and uses its output as loop elements to
run another program.
</p>

<h2> Interface </h2>

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

<pre>
     forbacktickx [ -E | -e ] [ -p | -P <em>maxpar</em> | -o <em>okcodes</em> | -x <em>breakcodes</em> ] [ -N | -n ] [ -C | -c ] [ -0 | -d <em>delim</em> ] <em>variable</em> { <em>gen...</em> } <em>loop...</em>
</pre>

<ul>
 <li> <tt>forbacktickx</tt> reads a
<a href="el_semicolon.html">block</a>,
<em>gen...</em>, and unquotes it. </li>
 <li> It runs <em>gen...</em> as a child process. <em>gen</em>'s
output must not contain a null character. </li>
 <li> It reads <em>gen</em>'s output as it needs,
<a href="el_transform.html#split">splitting</a> it automatically. </li>
 <li> For every argument <em>x</em> in the split output,
<tt>forbacktickx</tt> runs <em>loop...</em> as a child process, with
<em>variable</em>=<em>x</em> added to its environment. </li>
 <li><tt>forbacktickx</tt> then exits 0.
</ul>

<h2> Options </h2>

<ul>
 <li> <tt>-p</tt>&nbsp;: parallel mode. Do not wait for a <em>loop...</em>
instance to finish before spawning the next one. <em>forbacktickx</em> will
still wait for all instances of <em>loop</em> to terminate before
exiting, though. </li>
 <li> <tt>-P</tt>&nbsp;<em>maxpar</em>&nbsp;: like <tt>-p</tt>, but with
a maximum of <em>maxpar</em> parallel instances, to avoid completely
clogging the machine in pathological cases. </li>
 <li> <tt>-o</tt>&nbsp;<em>okcodes</em>&nbsp;: <em>okcodes</em> must
be a comma-separated list of exit codes. If the <tt>-p</tt> flag
hasn't been given and <em>loop</em> exits with one of the codes in
<em>okcodes</em>,
forbacktickx will run the following instances of the loop, but if the exit code is
not listed in <em>okcodes</em>, forbacktickx will exit immediately with an
<a href="exitcodes.html">approximation</a> of the same exit code. </li>
 <li> <tt>-x</tt>&nbsp;<em>breakcodes</em>&nbsp;: like the previous
option, but with inverted meaning - the listed exit codes are codes
that will make forbacktickx break the loop and exit, and the unlisted exit
codes will make it keep looping. </li>
 <li> <tt>-e</tt>&nbsp;: no autoimport. This is the default. </li>
 <li> <tt>-E</tt>&nbsp;: autoimport. Instead of spawning
<em>loop...</em>, spawn <tt>importas -ui <em>variable</em> <em>variable</em>
<em>loop...</em></tt>. This substitutes <em>variable</em> into the command
line instead of putting it into the environment. </li>
</ul>

<p>
 Other options are similar (in name and functionality) to the switches
passed to <a href="el_transform.html">control a substitution mechanism</a>,
on purpose; however, <tt>forbacktickx</tt> does not call the substitution
mechanism and has its own semantics for those options.
</p>

<ul>
 <li> <tt>-N</tt>&nbsp;: store the whole line in <em>variable</em>,
including the terminating newline (or other delimiter). </li>
 <li> <tt>-n</tt>&nbsp;: chomp a terminating delimiter from the line from
stdin before storing it into <em>variable</em>. This is the default. </li>
 <li> <tt>-C</tt>&nbsp;: crunch. If there is an empty line (i.e. that
only contains a delimiter), do not call <em>loop</em>. If this option is
given, <em>and</em> chomping is active, <em>and</em> the last line of stdin
is not terminated by a delimiter, then this last line will not be processed. </li>
 <li> <tt>-c</tt>&nbsp;: do not crunch, call <em>loop</em> even if
the line is empty. This is the default. </li>
 <li> <tt>-0</tt>&nbsp;: accept null characters on its stdin,
using them as delimiters. If this option and a <tt>-d</tt> option are
used simultaneously, the rightmost one wins. </li>
 <li> <tt>-d&nbsp;<em>delim</em></tt>&nbsp;: use the characters in string
<em>delim</em> as delimiters for a line. Default is "<tt>\n</tt>", meaning
the input is only split on newlines. </li>
</ul>

<h2> Notes </h2>

<ul>
 <li> You can start <em>loop...</em> with "importas -u <em>variable</em> <em>variable</em>"
to perform variable substitution. </li>
 <li> forbacktickx is now implemented as a wrapper around the
<a href="pipeline.html">pipeline</a> and
<a href="forstdin.html">forstdin</a> commands, with calls to
<a href="fdmove.html">fdmove</a> to ensure that <em>loop...</em> is called
with the proper standard input. </li>
</ul>
 
</body>
</html>