Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>From <a href="http://www.gnu.org/software/bash/manual/bashref.html#Process-Substitution" rel="nofollow"><code>Process Substitution</code></a> </p> <blockquote> <p>The process list is run with <strong>its input or output connected to</strong> a FIFO or some file in <strong>/dev/fd</strong>. <strong>The name of this file is passed as an argument to the current command</strong> as the result of the expansion. If the >(list) form is used, <strong>writing to the file will provide input for list</strong>.</p> </blockquote> <p>What happens with <code>echo "test" &gt;(wc)</code>?</p> <p>The file <code>/dev/fd/63</code> is opened for connecting <code>echo test</code> with <code>wc</code>. <code>wc</code> is started with it's input connected to <code>/dev/fd/63</code>. Then the name of this file (<code>/dev/fd/63</code>) is passed as an argument to the current command (<code>echo "test"</code>), resulting in <code>echo "test" /dev/fd/63</code>. This is why you see </p> <pre><code>test /dev/fd/63 </code></pre> <p>as output. <code>wc</code> waits for input, but since <code>echo</code> doesn't write to <code>/dev/fd/63</code>, the count will be <code>0</code>.</p> <p>If you want this to work, you must create a script, which takes the last argument and echos the first <code>N-1</code> arguments into the last </p> <pre><code>#! /bin/bash echo "${@:1:$(($# - 1))}" &gt;${@: -1} </code></pre> <p>When you call this </p> <pre><code>bash script.sh test &gt;(wc) </code></pre> <p>you will see the expected output </p> <pre><code>1 1 5 </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload