| 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 | comm <(head -n 2 $f) <(tail -n 2 $f) |
| 7 | # stdout-json: "1\n\t\t2\n\t3\n" |
| 8 | |
| 9 | ### Non-linear pipeline with >() |
| 10 | stdout_stderr() { |
| 11 | echo o1 |
| 12 | echo o2 |
| 13 | |
| 14 | sleep 0.1 # Does not change order |
| 15 | |
| 16 | { echo e1; |
| 17 | echo warning: e2 |
| 18 | echo e3; |
| 19 | } >& 2 |
| 20 | } |
| 21 | stdout_stderr 2> >(grep warning) | tac >out.txt |
| 22 | wait $! # this does nothing in bash 4.3, but probably does in bash 4.4. |
| 23 | echo OUT |
| 24 | cat out.txt |
| 25 | # PROBLEM -- OUT comes first, and then 'warning: e2', and then 'o2 o1'. It |
| 26 | # looks like it's because nobody waits for the proc sub. |
| 27 | # http://lists.gnu.org/archive/html/help-bash/2017-06/msg00018.html |
| 28 | # stdout-json: "OUT\nwarning: e2\no2\no1\n" |