Reputation: 587
echo aaa > >(echo $(cat))
In my opinion, it should print "aaa" and exit, but it stops unless I press enter button, why?
Thx
Upvotes: 1
Views: 814
Reputation: 780688
It's not waiting for you to press enter before it finishes. The command finishes immediately, but its output is printed after the next shell prompt. it looks like:
barmar@dev:~$ echo aaa > >(echo $(cat))
barmar@dev:~$ aaa
This is because the shell doesn't wait for the command in the process substitution to finish, it just waits for the echo
command to complete. So it prints the next prompt as soon as the echo
is done, and then echo $(cat)
runs asynchronously and prints its output.
If you type another command at this point, it will work. It just looks weird because the output was printed after the prompt. You only need to press Enter if you want a new prompt on its own line.
Upvotes: 8
Reputation: 1
$(cat)
is the same as the
`cat`
command. It runs cat
and is expanded to its output.
But without any arguments cat
(actually /bin/cat
, see cat(1)) is reading the stdin and copying it into stdout till end of file.
So your shell is running that, so is waiting for your input.
The shell is expanding in specific order.
Upvotes: 2