sed behaving strangely when -n and the delete command are combined

Rob Landley rob at landley.net
Tue Jul 14 04:50:11 UTC 2009


On Monday 13 July 2009 18:04:17 Denys Vlasenko wrote:
>I thought that since your mail does not contain a patch,
>it effectively says that I wrote bad code. Without providing
>a better alternative. I tried this approach too.
>Does not make me new friends :(

I am _way_ stale on this codebase, and most of what I remember about sed is 
that it was fiddly.  If I'm reluctant to come up with a patch, it's because I 
expect to hit things like the -1 vs -2 mistake even in code I wrote.

Remember that I did _three_ complete rewrite passes over "mount" before I was 
happy with the result.  I always meant to do another pass over sed to simplify 
things, make them more obvious, properly fix the embedded zero stuff... but 
never got around to it.

> > That patch (to 1.14.1) handles both of the cases you listed just fine. 
> > Why you're posting enormous patches to address something this simple is
> > what I'm trying to _understand_.
>
> Because I'm stupid. B]

Nah, sed is evil.  It took me at least a month to wrap my head around Glenn's 
code back in 2003, and I'm reluctant to touch it again without a week to 
devote to coming back up to speed, because I don't remember the details.  Just 
that there were a lot of them.

> > On a related note, the busybox multiplexer also appears to be broken, at
> > least for allnoconfig+sed.  When I just tried it (make distclean, make
> > allnoconfig, make menuconfig, switch on editors->sed, make) it went:
> >
> > $echo -e "first\nsecond\nthird\nfourth" | ./busybox sed -n '1d;1,3p'
> > sed: unmatched 'e'
> > bash: echo: write error: Broken pipe
>
> That's actually a feature. If you have *only one* applet,
> multiplexer is disabled. :) It does not matter how you rename
> the binary, it will work as that applet.

Ah.  Is this documented somewhere that I missed?

I don't suppose there's a way to get the makefile to rename the "busybox" 
binary to "sed" in that case?  (Since "busybox" is a command with specific 
semantics, and it's not actually creating one of those, having a silent 
behavior change like that is a bit of a gotcha.)  That's part of the reason 
the old make individual stuff I did was an external build script.

I should probably write up the approach I took in toybox and see how what 
busybox is doing now differs, I'm a few years out of date with thinking in 
busybox terms...

> > (When I say "I break things", I mean that trying to test the fix for one
> > bug and encountering three other unrelated bugs along the way is a normal
> > afternoon for me.  It always has been.  I don't know why.  It's kind of
> > annoying, really.)
>
> Yeah, build systems tend to keep working correctly only in usage cases
> which are frequently executed by developers. I use "make -j" very rarely.
>
>
> I am committing your patch. Thanks!

Glad I could help.  Sorry it took so long to express what I meant clearly.

Rob
-- 
Latency is more important than throughput. It's that simple. - Linus Torvalds



More information about the busybox mailing list