sed command in busybox
John Kelly
jakelly at shtc.net
Sun Nov 20 04:15:10 UTC 2005
On Sun, 20 Nov 2005 13:08:26 +1100, Glenn L McGrath
<bug1 at iinet.net.au> wrote:
>> You can search the comp.unix.shell archives for:
>> retain_quoted v0.004
>Found it, i got an error trying to run it under busybox sed, "bad
>option in substitution expression", it has commands like "s/foo/bar/
>#baz" i think technically it should have a semicolon in there,
>i.e. "s/foo/bar/;#baz"
>"Command verbs other than {, a, b, c, i, r, t, w, :, and # can be
>followed by a semicolon, optional <blank>s, and another command verb."
Maybe that needs cleaning up. But since it works with GNU, I have
little incentive.
>I got it to run, and i see its output is different than GNU sed, I will
>see if i can derive a simpler test from it.
It's different because busybox sed does not recognize the \n escape
within the bracket expressions, and that causes the matches to fail.
I discovered that by changing all the occurrences of \n to an unusual
character like @ and omitting that character from my test input. And
since the G commands put newlines in the pattern space, I also had to
add s commands to replace the newlines with @, after each G command.
But once I solved that problem, further testing with various inputs
showed that some inputs caused busybox sed to go hawire and produce
crazy output. At that point, I concluded busybox sed is not up to the
rigors of my script. Admittedly, it's not your typical sed script.
The long regex near the top:
^(([^"'\n]*([^\"'\n]|\\"|\\'))*)("|')(.*)
was difficult to derive and is difficult to understand, unless you
convert it to the symbolic form I used during development and testing
^(([^QqN]*([^bQqN]|\bQ|\bq))*)(Q|q)(.*)
where you can feed it symbolic input from the command line to see how
it works. That helped me appreciate the programmers who wrote the GNU
sed C code which can properly handle it.
More information about the busybox
mailing list