Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is this Bash (and/or other shell?) construct called?

What is the construct in bash called where you can take wrap a command that outputs to stdout, such that the output itself is treated like a stream? In case I'm not describing that so well, maybe an example will do best, and this is what I typically use it for: applying diff to output that does not come from a file, but from other commands, where

cmd 

is wrapped as

<(cmd)

By wrapping a command in such a manner, in the example below I determine that there a difference of one between the two commands that I am running, and then I am able to determine that one precise difference. What is the construct/technique of wrapping a command as <(cmd) called? Thanks

[builder@george v6.5 html]$ git status | egrep modified | awk '{print $3}' | wc -l
51
[builder@george v6.5 html]$ git status | egrep modified | awk '{print $3}' | xargs grep -l 'Ext\.define' | wc -l
50
[builder@george v6.5 html]$ diff <(git status | egrep modified | awk '{print $3}') <(git status | egrep modified | awk '{print $3}' | xargs grep -l 'Ext\.define')
39d38
< javascript/reports/report_initiator.js

ADDENDUM The revised command using the advice for using git's ls-file should be as follows (untested):

diff <(git ls-files -m) <(git ls-files -m | xargs grep -l 'Ext\.define')
like image 231
Dexygen Avatar asked Dec 23 '11 13:12

Dexygen


3 Answers

It is called process substitution.

like image 102
Mat Avatar answered Oct 26 '22 23:10

Mat


This is called Process Substitution

like image 25
MattH Avatar answered Oct 26 '22 22:10

MattH


This is process substitution, as you have been told. I'd just like to point out that this also works in the other direction. Process substitution with >(cmd) allows you to take a command that writes to a file and instead have that output redirected to another command's stdin. It's very useful for inserting something into a pipeline that takes an output filename as an argument. You don't see it as much because pretty much every standard command will write to stdout already, but I have used it often with custom stuff. Here is a contrived example:


$ echo "hello world" | tee >(wc)
hello world
      1       2      12
like image 43
frankc Avatar answered Oct 27 '22 00:10

frankc