Re:Shell Magic: Set Operations with uniq
by partycoder on Tuesday May 29, 2018 @07:31PM
(#17183655)
Can also use
To use the output of a command as input.
This also works with diff and other commands.
[ Parent
| on HN ]
More accurately, it can be used for any command which expects a file and doesn't do anything too weird in reading it (e.g. doesn't seek to the beginning and read it again)
The '<( ... )' is just giving the path to that command's stdout as a file descriptor.
$ ls <(echo hi)
/proc/self/fd/11
$ vi <(echo hi)
# opens vi with 'hi' as the contentsThank you. I was just thinking of looking into how it was implemented.
It is called "process substitution", and can work the other way around:
http://www.tldp.org/LDP/abs/html/process-sub.html
With fish:
https://fishshell.com/docs/current/commands.html#psub
But there it only works one way:
Re:Shell Magic: Set Operations with uniq
by scintill76 on Tuesday May 29, 2018 @07:56PM
(#17183777)
Note that this is a bash feature; other shells may have different syntax.
It's the same in ksh at least, so one is covered in the BSDs. It could be also implemented as a separate tool, but not as convenient, because of additional quoting - I did once.
I use it in my frugal SSG project [0] to remove HTML files for every removed source file. It's great to use it this way as it doesn't use temp files.
[0] https://gist.github.com/hadrianw/060944011acfcadd889d937b960...