As you've said, you shell script will die if it attempts to write to a closed pipe. It won't if it doesn't.
If you remove the second line, a.sh
doesn't attempt to write to its stdout
after echo 3
, so it has no reason to fail.
Removing the first line might not get you the same result every time you run your test. There's a timing issue. If the last two echo
statements are processed before head
attempts to read from it's input (and terminate because it's reached 3 lines), then a.sh
won't get a broken pipe error. If the timing is such that head
does a read in between the two echo
s, then a.sh
will get the pipe error, and die.