Installing FreeBSD’s ed(1) on a Linux dis­tri­b­u­tion

Created: Fri Feb 1 21:13:37 CET 2019

Last mod­i­fied: Sun Feb 3 03:35:34 CET 2019

I was­n’t happy with GNU ed, so I de­cided to use the FreeBSD ver­sion.

Let’s say I want to re­place every spaces with a new­line.

g/ / \
s/ /\

For some rea­son, the GNU stan­dard re­quires ed(1) to er­ror out when a new­line is used in a global com­mand’s re­place­ment string. This lim­i­ta­tion is im­ple­mented since 1.4.1 in regex.c.

(I kept the orig­i­nal for­mat­ting.)

if( **ibufpp == '\n' )
  if( isglobal && (*ibufpp)[1] != 0 )
    { set_error_msg( "Invalid newline substitution" ); return false; }

I found that sim­ply com­ment­ing out that part seems to do the trick.

Now, if you re­ally want to switch to FreeBSD’s ed(1), here are the steps.

git clone ''
cd 'freebsd/bin/ed'

Now we need to com­ment out any call to the __FBSDID di­rec­tive.

sed -i 's/^\(__FBSDID\)/\/\/\1/g' *.c

And we need to get rid of any call to strlcpy which is not avail­able on my dis­tri­b­u­tion, and re­place them with calls to strncpy.

You can ei­ther #define strlcpy strncpy in ed.h or run the fol­low­ing sed(1) com­mand.

sed -i 's/strlcpy/strncpy/g' *.c

And now for the com­pi­la­tion step:

CC=gcc # clang
$CC -o ed glbl.c buf.c io.c re.c sub.c undo.c main.c

source code