[PATCH 0/2] scripts/config: Use ERE (-E) and in-place editing (-i) in sed portably
From: Rong Zhang
Date: Sat Jun 06 2026 - 18:12:54 EST
The use of Extended Regular Expressions and in-place editing was removed
by commit 83e8b90e1d2c ("scripts/config: use sed's POSIX interface").
Before that, the script used `-r' to enable ERE, which is indeed
non-portable. However, POSIX.1-2024 [1][2] has accepted `-E' as a
standard option to use ERE for matching, and major sed implementations
(GNU, FreeBSD, OpenBSD, NetBSD, macOS) have supported `-E' for over two
decades, so it makes no sense to use Basic Regular Expressions any more.
Hence, we can safely take the advantage of ERE and merge chained calls
to sed.
Before the said commit, the script used bare `-i' to enable ERE while
skipping creating a backup file. In fact, major sed implementations
have 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. Hence, creating a backup file
with a .swp extension (the same name as the current temporary file)
anyway makes it portable. The backup file will be deleted on exit.
A rough benchmark with ~1000 editions showed a 48.6% speedup (8.78s =>
4.51s, GNU sed) in total. The FreeBSD sed showed a similar speedup.
I split the series into two patches so that PATCH 2 can be dropped if
strong POSIX compliance is desired.
Link: https://pubs.opengroup.org/onlinepubs/9799919799/utilities/sed.html [1]
Link: https://austingroupbugs.net/view.php?id=528 [2]
Signed-off-by: Rong Zhang <i@xxxxxxxx>
---
Rong Zhang (2):
scripts/config: Use POSIX standard ERE (-E) in sed
scripts/config: Use in-place editing (-i) in sed portably
scripts/config | 33 ++++++++++++++-------------------
1 file changed, 14 insertions(+), 19 deletions(-)
---
base-commit: 8e65320d91cdc3b241d4b94855c88459b91abf66
change-id: b2d6414d-config-sed-633649d7b0de
Thanks,
Rong