Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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?

like image 337
zjhui Avatar asked Sep 26 '26 13:09

zjhui


1 Answers

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.

like image 158
Michael Hoffman Avatar answered Sep 28 '26 02:09

Michael Hoffman



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!