Shell pipes and in-place insanity
fakedrake.github.ioI think this behaviour is supposed to be a feature of shell. Pipelines are executed in parallel.
Also, see `sponge` from `moreutils` (http://kitenet.net/~joey/code/moreutils/):
$ man sponge
...
sponge reads standard input and writes it out to the specified file.
Un‐like a shell redirect, sponge soaks up all its input before opening the output file.
This allows constructing pipelines that read from and write to the same file.This is the expected behavior of pipes[0]. A quick look at Lists [1] clears up how you can control this a little better (+Job Control). jamesdutc also linked to sponge, which may suit your usecase as well.
[0] https://www.gnu.org/software/bash/manual/bashref.html#Pipelines
[1] https://www.gnu.org/software/bash/manual/bashref.html#ListsThat 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.
You are right I should have clarify that. thank you
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. :)
NB: If you're going to use CSS styling for code examples, choose foreground and background colors, as well as text sizes, which are actually legible.
Monospace fonts, black on white, at default sizes, are your best bets.
Counteranecdatum for the author: I find your choice of foreground and background colors, syntax highlighting colors, font style and size, and line length inside your code blocks to be quite legible and pleasant to read.
Please make these sorts of choices again in the future!
Um... I see almost-black Courier New on off-white, at 13px and a slightly increased line-height. That seems fine to me.
The body text is approximately legible size, but low contrast.
The code examples are all but unreadable.
http://i.imgur.com/ogS9yat.png
Here's a quick improvement for legibility. I'm not claiming a thing of beauty.
http://i.imgur.com/mW880fB.png
My general style guidelines are included here:
I see your point about the larger fonts but I have used the sunburn theme for a while in my editor (not anymore thought in favor of slightly customized naquadah[1] ) and I feel quite a bit more comfortable reading code in familiar coloring. I chose this color scheme because sunburn dark is quite popular.
[1] http://rvfblog.wordpress.com/2011/03/07/using-naquadah-theme...
I still find it very difficult to read. Even expanding the font size isn't sufficient.
That's a pity.
Perhaps your color vision is now at the point where you should consider loading an accessibility stylesheet into your browser. I don't look forward to the day when I am required to do this, but I do know that it will inevitably arrive.
I use Stylebot to modify sites' CSS.
1188 stylesheets and counting.
Huh, this is what I see: https://i.imgur.com/fcNfpM3.png
It seems that some of the stylesheets are broken for HTTPS. Note that this is not https-everywhere breaking the site; simply switch the URL to https://, and you will see what I see.