[Toybox] A brief argument in favor of implementing ed

Rob Landley rob at landley.net
Fri Nov 25 10:40:09 PST 2011


On 11/22/2011 08:56 AM, Robert Thompson wrote:
> Much like more, it can successfully work in truly messed-up
> environments. It needs no cursor-control at all to do its basic job.

I'm implementing sed.

> It's obnoxious to use interactively, true, but can be tiny and easily
> pays for itself the first time you have to work blind to modify a file.

With sed.

> It's also more useful than sed for modifying files from scripts. More
> than once, I have used it to let a shell script change a config option
> in a config file in cases where sed was inappropriate or missing/broken.

A) inappropriate how?  It started out as a streaming version of "ed"
rather than one that needed to load the entire file into a buffer to
operate on it.

B) The one in toybox shouldn't be missing or broken.

> If you're a little careful, you can use it to change just the option you
> care about without even damaging the surrounding comments.

You can do that with sed, yes.

> And unlike
> sed, it already takes care of the write-out phase without you having to
> explicitly sed to a tempfile, rename, handle possible error cases.

I'm implementing the sed -i option that gnu's had for a decade and
busybox has had since I implemented it circa 2006 or so.  (My first big
busybox applet rewrite was "sed", that's how I got involved in busybox
development in the first place.  Alas, I don't have a clean "just my
code" version of that one, so I have to rewrite it.)

> If it's not available, it is possible to work around it, but it does
> really simplify a lot of things that are likely to be needed in minimal
> environments.

Lots of people and scripts still use sed.  I don't know anybody under
the age of 50 who still uses ed, and have never encountered it in a script.

After I do vi, if there's sufficiently small overhead I might do a
version of "sed" that operates on a buffer just out of SUSv4
completionism.  But as priorities go, it's below implenting "asa":

  http://opengroup.org/onlinepubs/9699919799/utilities/asa.html

Rob

 1322246409.0


More information about the Toybox mailing list