[BusyBox] Re: Bug Report:BB 1.00 sed

Rob Landley rob at landley.net
Tue Nov 2 07:06:15 UTC 2004


On Monday 01 November 2004 03:17, Hiroshi Ito wrote:

> > echo -n woo > woo
> > sed -e h -e g woo
> > echo "fish" | sed -e '/woo/h' -e "izap" -e 's/woo/thingy/' -e '/fish/g'
> > woo -
>
>  This example makes me deep consideration to understand it.

It's one of the more conceptually messy bits of the code, yes.  No clear spec 
here...

>  but Now, I understand it. and report difference of GNU sed
>  and BB's sed.
> ------
>  With your
> patch(http://www.busybox.net/lists/busybox/2004-October/013028.html ) /tmp
> # echo -n test > a
> /tmp # sed -n p a /dev/null
> test/tmp #			<= GNU sed appends a new line, but not yours.

Hmmm...

I was doing it the way I did it due to some test I ran that said doing it that 
way was The Right Thing, but it's been a year and my notes are in the backups 
from the laptop that got trashed, which are a bit disorganized...

I _think_ leaving busybox sed how it is is probably a decent thing.  The last 
line it printed didn't end with a newline in the source file, and it never 
needed to insert one to keep it distinct from another line printed 
afterwards.  Therefore what busybox did makes sense.  In the absence of some 
spec saying that doing what makes sense is _wrong_... :)

> ------
> --- GNU sed ---
> [root at titan root]# echo -n test > a
> [root at titan root]# sed -n p a /dev/null
> test
> [root at titan root]#

GNU is logically treating an empty file as if it contains a single newline.  
Therefore, these two lines presumably produce different outputs in gnu sed, 
but identical outputs in busybox sed:

sed "" test /dev/null
cat test /dev/null | sed ""

Then again, these two produce also different outputs (but the both busybox and 
gnu produce the same two outputs), and it makes sense that they do...

sed "" test test
cat test test | sed ""

It's a definitional question.  GNU is applying the newline inserting behavior 
to the input, and busybox is applying it to the output.  Unless somebody 
shows a real-world problem, I agree it's not worth a patch.  Maybe document 
the deviation...

Rob




More information about the busybox mailing list