Skip to content

[parser] 命令位置 ( 的解析/诊断分歧:for() 与模式串中 ( 被当成复合结构吞到 EOF,其一 rc=0(GNU 立即报 unexpected token '(' rc=2 + 源行回显) #516

Closed

Description

@caomengxuan666

复现

x='abc{def'; echo \${x%%[<{(]*}    # F181
for()                               # F126
片段 GNU bash 5.3.0 rubash 764b9dd
F181 bash: line 1: syntax error near unexpected token '(' + 源行回显两行,rc=2 ...: line 2: syntax error: unexpected end of file from `(' command on line 1,rc=0
F126 bash: line 1: syntax error near unexpected token '(' + `for()' 回显,rc=2 ...: line 2: syntax error: unexpected end of file from `for' command on line 1,rc=2

根因

未加引号的 ( 是元字符:跟在词后面(F181 的 [<{(]*}、F126 的 for 后)应立即报 "syntax error near unexpected token ('" 并回显源行。rubash 的 lexer 反而**打开了 (/for` 复合结构**,吞到 EOF 才报 "unexpected end of file from X command"。两片段同构(消息形状一致地错);F181 额外退出码为 0(语法错误置位缺失,与"stdin 语法错误 rc=0"issue 的退出码管线交叉引用)。

规范/源码依据

  • XCU 2.3 Token Recognition rule:( 为控制操作符,词法阶段即终结当前词。
  • bash 诊断三形态(near-token / EOF / matching-quote)+ 源行回显(bash error.c:parser_error → 报 token + 打印当前输入行)。

跨实现互证(huck)

证据

  • 语料出处:extglob_command_sub_diff_check.sh:31(F181);parser_syntax_errors_diff_check.sh:51(F126)
  • 复核:764b9dde 仍复现;旧构建 41de831 行为一致

Activity

  1. added
    bug
    P2-medium
    on Oct 12, 2026
  2. caomengxuan666 commented on Oct 12, 2026

    @caomengxuan666
    MemberAuthor

    Fixed by #576 (Wave4a). Vendored-bash anchors and RED-then-GREEN regression evidence in the PR.

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    P2-mediumbug

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions