5 ms·
Shell pipes and in-place insanity
- templeos2 12y agoThere's not really a STDIN or STDOUT. The vision is a souped-up 64-bit modern C64. Linux wants to be a mainframe.
- mtdewcmu 12y agoThat 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 12y agoYou are right I should have clarify that. thank you
- mtdewcmu 12y agoI'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 12y agoNB: 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.
- simoncion 12y agoCounteranecdatum 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!
- LukeShu 12y agoUm... I see almost-black Courier New on off-white, at 13px and a slightly increased line-height. That seems fine to me.
- dredmorbius 12y agoThe 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 12y agoI 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-in-emacs/ http://rvfblog.wordpress.com/2011/03/07/using-naquadah-theme...
- dredmorbius 12y agoI still find it very difficult to read. Even expanding the font size isn't sufficient.
- 12y ago
- jamesdutc 12y agoI 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 12y agoThis 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