blob: 99be53eedb556530da5ea8b6ec3274ff963e2078 (
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
|
<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 if command</title>
<meta name="Description" content="execline: the if command" />
<meta name="Keywords" content="execline command if" />
<!-- <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>if</tt> program </h1>
<p>
<tt>if</tt> performs conditional execution.
</p>
<h2> Interface </h2>
<p>
In an <a href="execlineb.html">execlineb</a> script:
</p>
<pre>
if [ -X ] [ -n ] [ -t | -x <em>exitcode</em> ] { <em>prog1...</em> } <em>prog2...</em>
</pre>
<ul>
<li> <tt>if</tt> reads <em>prog1...</em> in a
<a href="el_semicolon.html">block</a>. It forks and executes it,
then waits for it to complete. </li>
<li> If <em>prog1</em> crashes, <tt>if</tt> prints an error message
then exits 128 plus the number of the signal that killed <em>prog1</em>. </li>
<li> If <em>prog1</em> exits with a non-zero code, <tt>if</tt> exits with an
<a href="exitcodes.html">approximation</a> of that code. </li>
<li> Else <tt>if</tt> execs into <em>prog2</em>. </li>
</ul>
<h2> Options </h2>
<ul>
<li> <tt>-X</tt> : treat a crash of <em>prog1</em> as a non-zero ("false") exit. This
is mostly useful in combination with <tt>-n</tt>. </li>
<li> <tt>-n</tt> : negate the test. If <em>prog1</em> exits true, then <tt>if</tt> will
exit 1; else it will exec into <em>prog2</em>. </li>
<li> <tt>-x</tt> <em>exitcode</em> : if <tt>if</tt> needs to exit, it will exit <em>exitcode</em>
instead of whatever else it would have exited. </li>
<li> <tt>-t</tt> : if <tt>if</tt> needs to exit, it will exit 0. This is equivalent
to <tt>-x 0</tt>. </li>
</ul>
<h2> Notes </h2>
<ul>
<li> <tt>if</tt> will exit if <em>prog1...</em> exits false. To use it in
an execline script that must run <em>prog3...</em> no matter the result of
the test, use a <tt>foreground</tt> wrapper:
<pre> foreground { if { <em>prog1...</em> } <em>prog2...</em> } <em>prog3...</em> </pre>
(in <a href="execlineb.html">execlineb</a> syntax) </li>
<li> <tt>if <em>prog1...</em> "" <em>prog2...</em></tt> is
equivalent to <tt>sh -c '<em>prog1...</em> && exec <em>prog2...</em>'</tt>. </li>
</ul>
</body>
</html>
|