public inbox for dash@vger.kernel.org
 help / color / mirror / Atom feed
From: Herbert Xu <herbert@gondor.apana.org.au>
To: classabbyamp <dev@placeviolette.net>
Cc: dash@vger.kernel.org
Subject: Re: regression in parameter expansion with backslash escaped strings
Date: Sat, 14 Mar 2026 18:34:57 +0900	[thread overview]
Message-ID: <abUrwVbgnvXBymLE@gondor.apana.org.au> (raw)
In-Reply-To: <11d5b164-f43e-4f8d-a3cc-895199bfe01c@placeviolette.net>

classabbyamp <dev@placeviolette.net> 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 <herbert@gondor.apana.org.au>
Home Page: http://gondor.apana.org.au/~herbert/
PGP Key: http://gondor.apana.org.au/~herbert/pubkey.txt

      reply	other threads:[~2026-03-14  9:35 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-03-05  1:32 regression in parameter expansion with backslash escaped strings classabbyamp
2026-03-14  9:34 ` Herbert Xu [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=abUrwVbgnvXBymLE@gondor.apana.org.au \
    --to=herbert@gondor.apana.org.au \
    --cc=dash@vger.kernel.org \
    --cc=dev@placeviolette.net \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox