Re: regression in parameter expansion with backslash escaped strings
Herbert Xu <[email protected]> Sat, 14 Mar 2026 18:34:57 +0900
| Newsgroups | org.kernel.vger.dash |
|---|---|
| Message-ID | <[email protected]> |
classabbyamp <[email protected]> wrote: > > 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 Yes this was an intentional change. Note that echo in dash has always interpreted escape sequences, as required by POSIX. It's just that the supported escape sequences have been expanded with the dollar single quote feature addition. Note that mksh behaves in the same way as dash. If you want to print a string verbatim, you should use printf instead of echo: printf '%s\n' "$str" instead of echo "$str" Cheers, -- Email: Herbert Xu <[email protected]> Home Page: http://gondor.apana.org.au/~herbert/ PGP Key: http://gondor.apana.org.au/~herbert/pubkey.txt