1

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?

Timur Shtatland
  • 12,024
  • 2
  • 30
  • 47
laurent01
  • 115
  • 8

2 Answers2

5

<(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
that other guy
  • 116,971
  • 11
  • 170
  • 194
1

Your example needs to be rewritten as this, for it to work as expected:

cat <(cat file1) <(cat file2)  
Timur Shtatland
  • 12,024
  • 2
  • 30
  • 47