[Bug 10821] New: ash: bash dollar not expanding inside quoted braced parameter expansion

bugzilla at busybox.net bugzilla at busybox.net
Tue Feb 27 11:55:02 UTC 2018


https://bugs.busybox.net/show_bug.cgi?id=10821

            Bug ID: 10821
           Summary: ash: bash dollar not expanding inside quoted braced
                    parameter expansion
           Product: Busybox
           Version: unspecified
          Hardware: All
                OS: Linux
            Status: NEW
          Severity: normal
          Priority: P5
         Component: Standard Compliance
          Assignee: unassigned at busybox.net
          Reporter: avihpit at yahoo.com
                CC: busybox-cvs at busybox.net
  Target Milestone: ---

Using current git busybox master (0e0209a) on Ubuntu 16.04 .

To reproduce, run inside ash:
(x=AB; echo "${x#$'\x41'}")

Expected result (and actual result in bash):
B

Actual result:
AB

If removing the quotes then it works as expected and like bash:
(x=AB; echo ${x#$'\x41'})
B

Other cases where busybox ash works correctly - i.e. like in bash:
(x=AB; y=A; echo "${x#$y}")  # B
echo  $'\x41'                # A
echo "$'\x41'"               # $'\x41'

And more cases where ash works correctly and demonstrates quoted vs unquoted
pattern inside quoted braces expansion:
(x="*ABC"; echo "${x#*B}")    # C
(x="*ABC"; echo "${x#"*B"}")  # *ABC


I don't think posix has anything specific to say, as it's a bash feature, but
it does seem to me that the outer quotes should not affect how things work
inside the braces, and the spec does say the following about parameter
expansion - note how it relates to the result of the expansion and not how the
expansion itself works:

If a parameter expansion occurs inside double-quotes:
- Pathname expansion shall not be performed on the results of the expansion.
- Field splitting shall not be performed on the results of the expansion, with
  the exception of '@' ; see Special Parameters.

And about braced quotes with word like ${parameter<something>word} :

In each case that a value of word is needed (based on the state of parameter,
as described below), word shall be subjected to tilde expansion, parameter
expansion, command substitution, and arithmetic expansion.

And about pattern expansion like  ${parameter#word} , specifically the last two
sentances about quotes:

In each case, pattern matching notation (see Pattern Matching Notation), rather
than regular expression notation, shall be used to evaluate the patterns.
If parameter is '*' or '@', the result of the expansion is unspecified.
Enclosing the full parameter expansion string in double-quotes shall not cause
the following four varieties of pattern characters to be quoted, whereas
quoting characters within the braces shall have this effect.

---------

Overall, it seems to me that bash-dollar should be expanded inside quoted
braced expansion, both because it seems to me that inside-the-braces should not
be affected by what happens with the result, because the posix spec seem to
support this approach in general, and because bash does so and ultimately it's
a bash feature.

Real world case: git-prompt.sh (distributed with git) uses such bash-dollar
inside braces expansion inside quotes (to split by newlines $'\n').

-- 
You are receiving this mail because:
You are on the CC list for the bug.


More information about the busybox-cvs mailing list