Hi Anthony,

Anthony Coulter wrote on Tue, Apr 11, 2017 at 04:59:06PM -0400:

> The man page for motd(5) says that all lines up to (but not including)
> the first line of /etc/motd are replaced by the kernel version at
> startup.
> 
> But if the first line is blank

I'm not sure how that might happen unless you deleted the first
line by hand ...

> the rc script ignores it and instead deletes everything between
> the first blank line and the second.

 ... but you still have a point that the misbehaviour when the first
line is blank is mildly annoying.

> This diff fixes that behavior.

But it also breaks the standard use case and never deletes anything
at all, because the address "0" never matches any line, so the
address pair never even gets started, so the "d" command never gets
executed at all.  So your diff is not OK.

Here is a correct implementation, also one line shorter.

OK?
  Ingo


Correct diff:

Index: rc
===================================================================
RCS file: /cvs/src/etc/rc,v
retrieving revision 1.493
diff -u -r1.493 rc
--- rc  26 Feb 2017 16:51:18 -0000      1.493
+++ rc  15 Apr 2017 15:13:35 -0000
@@ -504,8 +504,7 @@
 fi
 if T=$(mktemp /tmp/_motd.XXXXXXXXXX); then
        sysctl -n kern.version | sed 1q >$T
-       echo "" >>$T
-       sed '1,/^$/d' </etc/motd >>$T
+       sed -n '/^$/,$p' </etc/motd >>$T
        cmp -s $T /etc/motd || cp $T /etc/motd
        rm -f $T
 fi



Wrong diff:

> Index: etc/rc
> ===================================================================
> RCS file: /cvs/src/etc/rc,v
> retrieving revision 1.493
> diff -u -p -r1.493 rc
> --- etc/rc    26 Feb 2017 16:51:18 -0000      1.493
> +++ etc/rc    11 Apr 2017 20:51:24 -0000
> @@ -505,7 +505,7 @@ fi
>  if T=$(mktemp /tmp/_motd.XXXXXXXXXX); then
>       sysctl -n kern.version | sed 1q >$T
>       echo "" >>$T
> -     sed '1,/^$/d' </etc/motd >>$T
> +     sed '0,/^$/d' </etc/motd >>$T
>       cmp -s $T /etc/motd || cp $T /etc/motd
>       rm -f $T
>  fi
> 

Reply via email to