bashhttp-redirectprocess-substitution

Redirection in join and cat


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?


Solution

  • <(cmd) is a process substitution. It shares a character with -- but is entirely unrelated to -- the < used for redirection:

    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