Skip to content

[bug] $[...] containing the enclosing quote char inside double quotes prints literally instead of bad-substitution #2441

Closed

Description

@caomengxuan666

Summary

Found during PR #2420's finisher pass, verified by the main session against GNU bash 5.3.20 (master and the #2420 branch behave identically): a $[...] body containing the SAME quote character as the enclosing double quotes is not diagnosed; the whole expansion prints literally with rc 0.

Repro

echo "i=$["1]"]"

GNU: bash: bad substitution: no closing ']' in i=$[ — the command is discarded, rc 1, nothing on stdout.
rubash: prints i=$["1]], rc 0.

Root area

Different mechanism from #2374/#2375 (both fixed): inside double quotes, the $[...] span end-finder treats the inner " as closing the enclosing quote context instead of scanning for the ] under the arithmetic-span rules, so no span is ever extracted and no error is raised. GNU diagnoses the unterminated span at expansion time (subst.c bad-substitution path). Fix by mechanism in the span extraction/end-finding for quoted contexts, not by special-casing this shape.

Fix destination

Arithmetic-expansion family, later wave (post-1.5.0-gate, land-if-clean).

Regression seed: the repro above (GNU: stderr diagnostic + rc 1 + empty stdout), plus neighbors probed at fix time (echo "i=$['1']", unquoted echo $["1"]).

Activity

  1. added
    bug
    on Nov 1, 2026
  2. added
    gnu-baseline
    area:expansion
    on Nov 1, 2026
  3. added a commit that references this issue on Nov 1, 2026
  4. caomengxuan666 commented on Nov 1, 2026

    @caomengxuan666
    MemberAuthor

    PR #2451 (merged, master d44dce1). Three-layer fix: dquote cookers bound spans by a skip_double_quoted port (subst.c:1014), the collector gains a segment-bounded mode, and walker arms raise the no-closing-bracket verdict on the DISCARD latch. My verification: issue2441 pins 6/6 green (scrubbed-fd harness).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

area:expansionbuggnu-baseline

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions