On 02/03/2018 18:00, Denys Vlasenko wrote:
On Wed, Feb 14, 2018 at 9:03 PM, Harald van Dijk <harald@xxxxxxxxxxx> wrote:
Currently:
$ dash -c 'foo=a; echo "<${foo#[a\]]}>"'
<>
This is what I expect, and also what bash, ksh and posh do.
With your patch:
$ dash -c 'foo=a; echo "<${foo#[a\]]}>"'
<a>
I was looking into this specific example and I believe it is a _bash_ bug.
The [a\]] is misinterpreted by it (and probably by many people).
The gist is: \] is not a valid escape for ] in set glob expression.
Glob sets have no escaping at all, ] can be in a set
if it is the first char: []abc],
dash can be in a set if it is first or last: [abc-],
[ and \ need no protections at all: [a[b\c] is a valid set of 5 chars.
Therefore, "[a\]]" glob pattern means "a or \, then ]".
Since that does not match "a", the result of ${foo#[a\]]}> should be "a".
Are you sure about this? "Patterns Matching a Single Character"'s first
paragraph contains "A <backslash> character shall escape the following
character. The escaping <backslash> shall be discarded." The shell does
this first. It removes the backslash (remembering that the following
character is escaped) before it starts interpreting the result as a
bracket expression, and so never gets to the point where the \ should be
taken literally.
case \] in [\]]) echo matched ;; esac
prints "matched" in all shells I can check.
Cheers,
Harald van Dijk
--
To unsubscribe from this list: send the line "unsubscribe dash" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html