Closed Fire3galaxy closed 9 years ago
Cat will stop reading when the pipe (or stdin if there is no pipe) closes.
On Sunday, March 8, 2015, Fire3galaxy notifications@github.com wrote:
echo "dlkfj" | cat Why does cat end in bash when this happens? It doesn't happen this way in my rshell.
My conception: "echo writes to pipe, exits, cat reads from pipe in next loop, reads until end of pipe, and exits having reached end of pipe or just waits for more input like with cin"
The reality seems to be the end of file thing, but my rshell waits for more cin (but doesn't echo to stdout because (I think) stdin has been set to pipe, so none of my inputs go through).
— Reply to this email directly or view it on GitHub https://github.com/mikeizbicki/ucr-cs100/issues/1092.
How did pipe close?
Also, what happens in bash with cat | cd? I type in 1 thing, nothing echoes, and then cat stops.
Cd reads that one thing and then closes its end of the pipe.
On Sunday, March 8, 2015, Fire3galaxy notifications@github.com wrote:
How did pipe close?
Also, what happens in bash with cat | cd? I type in 1 thing, nothing echoes, and then cat stops.
— Reply to this email directly or view it on GitHub https://github.com/mikeizbicki/ucr-cs100/issues/1092#issuecomment-77787357 .
EDIT: Nevermind this post EDIT 2: Oh, you were answering my followup. That doesn't answer why cat stopped. In the case of my first response below, cd doesn't take stdin, but it does ignore it and the program will close the pipe.
But cd doesn't take in arguments or use stdin
oh wait, sorry, talking about cat. Ok then, cat closes it. On its own though?
Confused with "Cd reads that one thing and then closes its end of the pipe." answer. Was that directed at my first question or my followup?
First question: what happens with echo "dlkfj" | cat
? (cat didn't take in more than what echo gave)
Second: what happens with cat | cd
? (cat stops after one input, (followup questions: cd doesn't change to home directory)
echo "dlkfj" | cat
Why does cat end in bash when this happens? It doesn't happen this way in my rshell.My conception: "echo writes to pipe, exits, cat reads from pipe in next loop, reads until end of pipe, and exits having reached end of pipe or just waits for more input like with cin"
The reality seems to be the end of file thing, but my rshell waits for more cin (but doesn't echo to stdout because (I think) stdin has been set to pipe, so none of my inputs go through).