What is happening behind bash forward process substitution? -
according wikipedia, "process substitution can used capture output go file, , redirect input of process."(http://en.wikipedia.org/wiki/process_substitution).
so, in own words, means process substitution, can take output of command , use input of command b. in other words, it's pipe(is correct?).
so if true, , if this:
echo "test" >(wc) then should expect following:
1 1 5 because understanding of above command similar following:
$echo "test" > tmp $wc tmp 1 1 5 tmp except don't make tmp file process substitution.
but instead following output:
test /dev/fd/63 this indicates somehow mental model incorrect. wrong?
i understand <(command). example
$diff <(head file1) <(head file2) perfectly makes sense. not >(command).
from process substitution
the process list run its input or output connected to fifo or file in /dev/fd. the name of file passed argument current command result of expansion. if >(list) form used, writing file provide input list.
what happens echo "test" >(wc)?
the file /dev/fd/63 opened connecting echo test wc. wc started it's input connected /dev/fd/63. name of file (/dev/fd/63) passed argument current command (echo "test"), resulting in echo "test" /dev/fd/63. why see
test /dev/fd/63 as output. wc waits input, since echo doesn't write /dev/fd/63, count 0.
if want work, must create script, takes last argument , echos first n-1 arguments last
#! /bin/bash echo "${@:1:$(($# - 1))}" >${@: -1} when call
bash script.sh test >(wc) you see expected output
1 1 5
Comments
Post a Comment