regression in parameter expansion with backslash escaped strings
classabbyamp <[email protected]> Wed, 4 Mar 2026 20:32:10 -0500
| Newsgroups | org.kernel.vger.dash |
|---|---|
| Message-ID | <[email protected]> |
Hello,
dracut-ng reports an issue with dash 0.5.13.1, where parameter expansion
of strings containing backslash-escaped sequences interprets the
sequences. This behaviour was bisected to
776424a8f9158bfe9f53aa55f931af9f73437caf parser: Add dollar single quote
A simple reproducing case is:
#!/bin/sh
str_replace() {
local in="$1"
local s="$2"
local r="$3"
local out=''
while [ "${in##*"$s"*}" != "$in" ]; do
chop="${in%%"$s"*}"
out="${out}${chop}$r"
in="${in#*"$s"}"
done
printf -- '%s' "${out}${in}"
}
str_replace "/dev/disk/by-label/dracut" '/' '\x2f'
echo
_name=$(str_replace "/dev/disk/by-label/dracut" '/' '\x2f')
echo "_name=$_name"
In bash and dash 0.5.12, this produces:
\x2fdev\x2fdisk\x2fby-label\x2fdracut
_name=\x2fdev\x2fdisk\x2fby-label\x2fdracut
In dash 0.5.13.1, this produces:
\x2fdev\x2fdisk\x2fby-label\x2fdracut
_name=/dev/disk/by-label/dracut
Github issue: https://github.com/dracut-ng/dracut-ng/issues/2280
--
classabbyamp