1 #!/usr/bin/env bash
2
3 #### Process sub input
4 f=_tmp/process-sub.txt
5 { echo 1; echo 2; echo 3; } > $f
6 cat <(head -n 2 $f) <(tail -n 2 $f)
7 ## STDOUT:
8 1
9 2
10 2
11 3
12 ## END
13
14 #### Process sub output
15 { echo 1; echo 2; echo 3; } > >(tac)
16 ## STDOUT:
17 3
18 2
19 1
20 ## END
21
22 #### Non-linear pipeline with >()
23 stdout_stderr() {
24 echo o1
25 echo o2
26
27 sleep 0.1 # Does not change order
28
29 { echo e1;
30 echo warning: e2
31 echo e3;
32 } >& 2
33 }
34 stdout_stderr 2> >(grep warning) | tac >$TMP/out.txt
35 wait $! # this does nothing in bash 4.3, but probably does in bash 4.4.
36 echo OUT
37 cat $TMP/out.txt
38 # PROBLEM -- OUT comes first, and then 'warning: e2', and then 'o2 o1'. It
39 # looks like it's because nobody waits for the proc sub.
40 # http://lists.gnu.org/archive/html/help-bash/2017-06/msg00018.html
41 ## STDOUT:
42 OUT
43 warning: e2
44 o2
45 o1
46 ## END