Re: [PATCH 2/2] scripts/config: Use in-place editing (-i) in sed portably
Nicolas Schier <[email protected]> Mon, 20 Jul 2026 21:40:58 +0200
| Newsgroups | org.kernel.vger.linux-kbuild,org.kernel.vger.linux-kernel |
|---|---|
| Message-ID | <178457645829.1375946.15414498343066263816.b4-review@b4> |
> 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 <[email protected]>
>
Reviewed-by: Nicolas Schier <[email protected]>
--
Nicolas