News for hackers. Stuff that matters.
Re:Shell pipes and in-place insanity by mtdewcmu on Saturday June 28, 2014 @05:05PM (#7959339)
That was a contrived example.

The shell sets up the pipe and file redirections for each process in the pipeline, then lets them go. It has no control over when the child processes read or write. It could be a race condition, but it's written in such a way that it appears that the file will get truncated before it can be read virtually 100% of the time.

Re:Shell pipes and in-place insanity by fakedrake on Saturday June 28, 2014 @09:31PM (#7960064)
You are right I should have clarify that. thank you
Re:Shell pipes and in-place insanity by mtdewcmu on Wednesday July 02, 2014 @02:22PM (#7978654)
I'm not sure if it's actually a race; it probably depends on how bash is implemented. But this prints what is expected:

echo "1\n2\n3\n4\n" > numbers && cat numbers | { sleep 1 && cat > numbers && cat numbers ; }

That's not exactly the same (because the redirection for cat #2 now happens in a subshell), but it shows that this is basically racy. :)