I wonder how redirection is used in this example from this site https://shapeshed.com/unix-join/
Here is the Input
$ cat wine.txt
White Reisling Germany
Red Riocha Spain
Red Beaunes France
$ cat reviews.txt
Riocha Meh
Beaunes Great!
Reisling Terrible!
Here is the command and the result
$ join -1 2 -2 1 <(sort -k 2 wine.txt) <(sort reviews.txt)
Beaunes Red France Great!
Reisling White Germany Terrible!
Riocha Red Spain Meh
But in this case double use of < doesn't work
$ cat file 1
Hello
$ cat file 2
World
I expect
$ cat <file1 <file2
Hello World
But result is
World
Do you guys have any idea?
<(cmd)
is a process substitution. It shares a character with -- but is entirely unrelated to -- the <
used for redirection:
<(cmd)
expands to a filename that you can open and read to get the program's output. You can pass as many filenames as you want to a command.< filename
opens a filename as file descriptor 0. Opening a new file on the same file descriptor overwrites and closes the previous one.Your process substitution example simply passes two separate filenames:
$ echo join -1 2 -2 1 <(sort -k 2 wine.txt) <(sort reviews.txt)
join -1 2 -2 1 /dev/fd/63 /dev/fd/6
If you similarly pass two filenames to cat
, you get the same kind of result:
$ cat file1 file2
Hello
World