
Shell pipes and in-place insanity - fakedrake
http://fakedrake.github.io/shell-pipes-and-in-place-insanity.html
======
jamesdutc
I 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/](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.

------
sikhnerd
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#Lists

------
mtdewcmu
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.

~~~
fakedrake
You are right I should have clarify that. thank you

~~~
mtdewcmu
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. :)

------
dredmorbius
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.

~~~
LukeShu
Um... I see almost-black Courier New on off-white, at 13px and a slightly
increased line-height. That seems fine to me.

~~~
dredmorbius
The body text is approximately legible size, but low contrast.

The code examples are all but unreadable.

[http://i.imgur.com/ogS9yat.png](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](http://i.imgur.com/mW880fB.png)

My general style guidelines are included here:

[https://news.ycombinator.com/item?id=6996064#up_6998399](https://news.ycombinator.com/item?id=6996064#up_6998399)

~~~
fakedrake
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...](http://rvfblog.wordpress.com/2011/03/07/using-naquadah-theme-in-
emacs/)

~~~
dredmorbius
I still find it very difficult to read. Even expanding the font size isn't
sufficient.

~~~
simoncion
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.

~~~
dredmorbius
I use Stylebot to modify sites' CSS.

1188 stylesheets and counting.

