Skip to content

Fix: Replace Perl-compatible \s with POSIX [ \t] in awk expressions for mawk compatibility - #441

Merged
Antynea merged 1 commit into
Antynea:masterfrom
reynegton:fix-awk-posix
Aug 24, 2026
Merged

Antynea merged 1 commit into
Antynea:masterfrom
reynegton:fix-awk-posix

Conversation

@reynegton

Copy link
Copy Markdown
Contributor

What was done:

Replaced the Perl-compatible regex escape sequence \s with the POSIX-compliant character class [ \t] in the awk expressions used to parse the UUID output from btrfs subvolume show.

Why it was done:

Currently, the script uses \s to match whitespace before UUID: in the awk command. While GNU awk (gawk) supports PCRE sequences like \s, standard POSIX awk implementations—most notably mawk, which is the default on Debian, Ubuntu, and their derivatives (like Linux Mint/LMDE)—do not support \s. When mawk evaluates /^\s*UUID/, it fails to match the whitespace, returning an empty UUID string. This causes a total failure during grub-mkconfig with the error: UUID of the root subvolume is not available.

What it solves:

This change ensures the script correctly identifies the UUID of the root and boot subvolumes on distributions utilizing mawk as the default awk implementation, preventing grub-mkconfig from crashing.

Regression risk:

None. The [ \t] character class is universally supported by the POSIX regular expression standard. It works flawlessly out-of-the-box on both gawk and mawk, meaning this fix maintains full backward compatibility with systems that currently use GNU awk, while seamlessly adding support for Debian-based systems.

@Antynea

Antynea commented Aug 24, 2026

Copy link
Copy Markdown
Owner

Hi,

Thanks for the write-up, the diagnosis is right and the reasoning is easy to follow.

I reproduced the failure and tested both forms against gawk, mawk, the One True Awk and busybox awk, using the exact tab-indented output of btrfs subvolume show. \s comes back empty on mawk and on the One True Awk, as you describe, while [ \t] matches correctly on all four.

#433 proposes the same fix with [[:space:]]. Both are correct; I'm going with yours because [ \t] matches the notation already used by the gsub on the same line, so each line keeps a single way of writing whitespace. For context, I argued against this class of fix on #433 back in May. I was wrong, and I've explained why over there.

I'll merge it shortly.

@Antynea
Antynea merged commit d83c4be into Antynea:master Aug 24, 2026
1 check passed
Antynea added a commit that referenced this pull request Aug 24, 2026
Since #441 the script no longer uses any gawk-specific awk construct.
All of its awk expressions were checked against gawk, mawk, the One True
Awk and busybox awk, and run unmodified on all four.

Declaring gawk advertised a requirement that the script never enforced
and that most users could not satisfy anyway, since mawk is the default
awk on Debian, Ubuntu and derivatives.

Refs #433, #441
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants