Bash process substitution: what does `echo >(ls)` do?

2.2k Views Asked by At

Here is an example of Bash's process substitution:

zjhui@ubuntu:~/Desktop$ echo >(ls)
/dev/fd/63
zjhui@ubuntu:~/Desktop$ abs-guide.pdf

Then I get a cursor waiting for a command.

/dev/fd/63 doesn't exist. I think what happens is:

  1. Output the filename used in /dev/fd
  2. Execute the ls in >(ls)

Is this right? Why is there a cursor waiting for input?

1

There are 1 best solutions below

1
On BEST ANSWER

When you execute echo >(ls), bash replaces this with echo /dev/fd/63 and runs ls with /dev/fd/63 connected to its standard input. echo does not use its arguments as file names, and ls does not use standard input. Bash will write your standard prompt but the output of ls comes after it. You can type in any Bash command there, you just lost the visual cue from the prompt, which is further up the screen.

echo >(ls) is not something that is likely to ever be useful.