@rl_dane

Then this is more mysterious.

#FreeBSD ports does not patch out #wordexp in the config processing from x11-wm/sway like #OpenBSD ports does, and command substitution via backticks in the Almquist shell wordexp builtin itself works.

https://github.com/freebsd/freebsd-ports/tree/main/x11-wm/sway/files

Try cranking up sh on the machine and running the wordexp directly in the Almquist shell. It works on my older version of FreeBSD. (I only substituted echo for hostname, as you can see.)

#Illumos has another #wordexp implementation (originating with Mortice-Kern, no less!) that expects a Korn (93) shell and uses its printf (and set -o), which might be tweakable to function with #OpenBSD's PD Korn shell; but like the GNU C library licence the Sun CDDL would likely be a problem.

https://code.illumos.org/plugins/gitiles/illumos-gate/+/refs/heads/master/usr/src/lib/libc/port/regex/wordexp.c

So if one is looking for "easily", where one just imports a compatibly-licenced and #KornShell-compatible existing implementation, the answer seems to be "No.".

#pdksh

usr/src/lib/libc/port/regex/wordexp.c - illumos-gate - Gitiles

Could #OpenBSD easily be improved to provide the standard #wordexp? It's a tricky one.

The FreeBSD and NetBSD implementations rely on sh being the Almquist shell with an undocumented wordexp builtin, but sh is a Korn shell variant on OpenBSD.

The GNU C library is not compatibly licensed. So its other problems are skippable.

The musl C library is MIT licensed and hands over to sh's printf. But OpenBSD has not taken anything from #musl before, as far as I can see.

https://git.musl-libc.org/cgit/musl/tree/src/misc/wordexp.c