4 ms·
Nobody knows this: the bash extension <(cmd) to pass the output of a command, as if it was a file, to another command. Example to diff the list of files in 2 di
by mrb 15y ago
Nobody knows this: the bash extension <(cmd) to pass the output of a command, as if it was a file, to another command. Example to diff the list of files in 2 directories (a and b) without using temporary files:
$ diff -u <(cd a && find . | sort) <(cd b && find . | sort)
Internally, bash creates a pipe and passes /dev/fd/XXX to the main command.
- sixtofour 15y agoJust diff the two directories. $ ls a b a: 1 2 3 4 b: 1 2 3 # Yours: $ diff -u <(cd a && find . | sort) <(cd b && find . | sort) --- /dev/fd/63 2011-11-20 02:50:21.919072726 -0700 +++ /dev/fd/62 2011-11-20 02:50:21.919072726 -0700 @@ -2,4 +2,3 @@ ./1 ./2 ./3 -./4 # Mine: $ diff -u a b diff -u a/1 b/1 --- a/1 2011-11-20 02:43:57.073130007 -0700 +++ b/1 2011-11-20 02:45:14.535912768 -0700 @@ -1 +1 @@ -1 +11 Only in a: 4 Maybe I'm missing something?
- jav 15y agoThe OP's example is diffing listings of the two directories whereas your command is asking diff to directly work on the directories themselves.
- robertskmiles 15y agoWhich means for example you could get that listing in any format, so you could for example spot changes in permissions or ownership if you included it in the listing.
- sixtofour 15y agoI stand enlightened.
- super_mario 15y agoYes, you are because the example was contrived. The point is that process substitution (as it is called) is available on systems that support named pipes. You could think of better uses for it.
- bho 15y agoThanks so much. I had to do this just earlier today and ended up using a tmp file.