I'm struggling to understand command redirection/reuse...
I understand there's the <(...) <(...)
methodology and the $( ... && ... )
techniques for combining output. But I don't really fully understand what the difference is (I realize that the (...)
dumps you inside a new shell, causing you to potentially jump dirs and lose any vars you haven't exported, but I'm unsure of how it effects the general redirection scheme) and I'm still quite confused as to how to do one-to-many redirection after skimming over the examples and instructions in:
Advanced Bash Scripting Guide 1
Advanced Bash Scripting Guide 2
My own attempts to play around with it have mostly resulted in "ambiguous redirect" errors.
For example, let's say I want to do a one liner given by the pseudocode below
CMD 1 && CMD 2 && CMD 3 --> (1)
CMD 4 (1) --> (2)
CMD 5 (1) --> CMD 6 --> (3)
CMD 7 (2) && CMD 8 (3) --> (4)
CMD 9 (2) --> (5)
CMD 10 (2) (3) -->(6)
VAR= echo (4) && echo (5) && echo (6)
Or as a process diagram
CMD 1 +CMD 2 && CMD 3
|\
| ---> CMD 5 ------> CMD 6-----\
V / V
CMD 4 ----------------u--------> CMD 10
| \ V /
| -------->CMD 7 + CMD 8 /
V | /
CMD 9 | /
\ | /
\ V /
--------> VAR <----------
Where outputs are designated as -->
; storage for reuse in another op is given by -->(#)
; and combination operations are given by &&
.
I currently have no idea how to do this in a single line without redundant code.
I want to truly master command redirection so I can make some powerful one-liners.
Hopefully that's clear enough... I could come up with proof of concept examples for the commands, if you need them, but the pseudocode should give you the idea.