Skip to content

Commit

Permalink
Write document about command connection
Browse files Browse the repository at this point in the history
  • Loading branch information
ryuichiueda committed Mar 28, 2017
1 parent 519fc51 commit f5f7ccb
Show file tree
Hide file tree
Showing 6 changed files with 116 additions and 3 deletions.
34 changes: 34 additions & 0 deletions docs/_sources/connection.txt
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,9 @@ In the case 1, ``echo 'else'`` is skipped because ``echo 'if'`` returns 0. In th
Then (?>)
=============================

Composition of if then else
-----------------------------

When two commands are connected with ``?>``, the right command runs only when the left command returns 0. When the right command returns any error, the script stops. We can implement "if-then-else" rules by combinations of ``>>, !>`` and ``?>`` as the following way.

.. code-block:: bash
Expand Down Expand Up @@ -169,3 +172,34 @@ The clunky shape of this if-then-else can be a little bit relieved by "do blocks
if

However, do blocks enhance computational costs.

Rule of ``?>`` at errors
-----------------------------

When the command at the right side of ``?>`` returns any error, the script stops immediately. In the following example, ``false`` at the second if-then connection stops the script.

.. code-block:: bash
:linenos:

$ cat then_stop.glue
import PATH

false ?> true
echo 'ok'

true ?> false
echo 'do not come here'

$ glue then_stop.glue
ok
Execution error at line 6, char 9
line6: true ?> false
^

Error at then part
process_level 0
exit_status 8
pid 51633
ERROR: 8

As shown in the output, the glue command gives 8 as the exit status when it stops by the right side of ``?>``.
55 changes: 54 additions & 1 deletion docs/connection.html
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,8 @@ <h2>5.3. Or (!&gt;)<a class="headerlink" href="#or" title="Permalink to this hea
</div>
<div class="section" id="then">
<h2>5.4. Then (?&gt;)<a class="headerlink" href="#then" title="Permalink to this headline"></a></h2>
<div class="section" id="composition-of-if-then-else">
<h3>5.4.1. Composition of if then else<a class="headerlink" href="#composition-of-if-then-else" title="Permalink to this headline"></a></h3>
<p>When two commands are connected with <code class="docutils literal"><span class="pre">?&gt;</span></code>, the right command runs only when the left command returns 0. When the right command returns any error, the script stops. We can implement &#8220;if-then-else&#8221; rules by combinations of <code class="docutils literal"><span class="pre">&gt;&gt;,</span> <span class="pre">!&gt;</span></code> and <code class="docutils literal"><span class="pre">?&gt;</span></code> as the following way.</p>
<div class="highlight-bash"><table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre> 1
2
Expand Down Expand Up @@ -264,6 +266,53 @@ <h2>5.4. Then (?&gt;)<a class="headerlink" href="#then" title="Permalink to this
</td></tr></table></div>
<p>However, do blocks enhance computational costs.</p>
</div>
<div class="section" id="rule-of-at-errors">
<h3>5.4.2. Rule of <code class="docutils literal"><span class="pre">?&gt;</span></code> at errors<a class="headerlink" href="#rule-of-at-errors" title="Permalink to this headline"></a></h3>
<p>When the command at the right side of <code class="docutils literal"><span class="pre">?&gt;</span></code> returns any error, the script stops immediately. In the following example, <code class="docutils literal"><span class="pre">false</span></code> at the second if-then connection stops the script.</p>
<div class="highlight-bash"><table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre> 1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20</pre></div></td><td class="code"><div class="highlight"><pre><span class="nv">$ </span>cat then_stop.glue
import PATH

<span class="nb">false</span> ?&gt; <span class="nb">true</span>
<span class="nb">echo</span> <span class="s1">&#39;ok&#39;</span>

<span class="nb">true</span> ?&gt; <span class="nb">false</span>
<span class="nb">echo</span> <span class="s1">&#39;do not come here&#39;</span>

<span class="nv">$ </span>glue then_stop.glue
ok
Execution error at line 6, char 9
line6: <span class="nb">true</span> ?&gt; <span class="nb">false</span>
^

Error at <span class="k">then</span> part
process_level 0
exit_status 8
pid 51633
ERROR: 8
</pre></div>
</td></tr></table></div>
<p>As shown in the output, the glue command gives 8 as the exit status when it stops by the right side of <code class="docutils literal"><span class="pre">?&gt;</span></code>.</p>
</div>
</div>
</div>


Expand All @@ -278,7 +327,11 @@ <h3><a href="index.html">Table Of Contents</a></h3>
<li><a class="reference internal" href="#pipeline">5.1. Pipeline</a></li>
<li><a class="reference internal" href="#and">5.2. And (&gt;&gt;)</a></li>
<li><a class="reference internal" href="#or">5.3. Or (!&gt;)</a></li>
<li><a class="reference internal" href="#then">5.4. Then (?&gt;)</a></li>
<li><a class="reference internal" href="#then">5.4. Then (?&gt;)</a><ul>
<li><a class="reference internal" href="#composition-of-if-then-else">5.4.1. Composition of if then else</a></li>
<li><a class="reference internal" href="#rule-of-at-errors">5.4.2. Rule of <code class="docutils literal"><span class="pre">?&gt;</span></code> at errors</a></li>
</ul>
</li>
</ul>
</li>
</ul>
Expand Down
2 changes: 1 addition & 1 deletion docs/searchindex.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Binary file modified manual_src/_build/doctrees/connection.doctree
Binary file not shown.
Binary file modified manual_src/_build/doctrees/environment.pickle
Binary file not shown.
28 changes: 27 additions & 1 deletion manual_src/connection.rst
Original file line number Diff line number Diff line change
Expand Up @@ -176,4 +176,30 @@ However, do blocks enhance computational costs.
Rule of ``?>`` at errors
-----------------------------
When the command at the right side of ``?>`` returns any error, the script stops immediately.
When the command at the right side of ``?>`` returns any error, the script stops immediately. In the following example, ``false`` at the second if-then connection stops the script.
.. code-block:: bash
:linenos:
$ cat then_stop.glue
import PATH
false ?> true
echo 'ok'
true ?> false
echo 'do not come here'
$ glue then_stop.glue
ok
Execution error at line 6, char 9
line6: true ?> false
^
Error at then part
process_level 0
exit_status 8
pid 51633
ERROR: 8
As shown in the output, the glue command gives 8 as the exit status when it stops by the right side of ``?>``.

0 comments on commit f5f7ccb

Please sign in to comment.