Re: [PATCH 2/2] scripts/config: Use in-place editing (-i) in sed portably

From: Nicolas Schier

Date: Mon Jul 20 2026 - 16:03:13 EST


> The use of in-place editing was removed by commit 83e8b90e1d2c
> ("scripts/config: use sed's POSIX interface").
>
> Before that, the script used bare `-i' to enable ERE while skipping
> creating a backup file. In fact, mojor sed implementations have
^^^^^
mojor -> major

> supported `-i' for over a decade. It's really doubtful if anyone would
> still compile Linux on a Unix system without it. The issue is more about
> how we use it:
>
> FreeBSD and macOS disallow bare `-i'. To skip creating a backup, an
> empty string ("zero-length extension") must be passed as a separate
> argument following `-i'.
>
> GNU and other BSDs accept bare `-i' to skip creating a backup, but
> disallow passing a zero-length extension.
>
> That being said, when thinking about it optimistically, using `-i' is
> portable as long as a backup is created.
>
> Use in-place editing (-i) in a portable manner by creating a backup file
> with a .swp extension (the same name as the current temporary file). The
> backup file will be deleted on exit.
>
> A rough benchmark with ~1000 editions showed a 14.4% speedup (5.27s =>
> 4.51s, GNU sed). The FreeBSD sed showed a similar speedup.
>
> Signed-off-by: Rong Zhang <i@xxxxxxxx>
>

Reviewed-by: Nicolas Schier <nsc@xxxxxxxxxx>

--
Nicolas