Skip to content

[parse] function-definition name word containing unquoted $( ) rejected — GNU accepts (breaks zZshFramework files.sh) #462

Closed

Description

@caomengxuan666

Construct (minimal repro)

f$()g() { :; }

rubash -n (fresh master a157656, release build):

tc.sh: line 1: syntax error near unexpected token `('

GNU bash 5.3.0 parses this function definition (the grammar accepts any WORD before ()).

Boundaries measured on the fresh build:

construct rubash -n GNU 5.3
f$()g() { :; } syntax error ok
f"$(echo x)"g() { :; } (quoted comsub) ok ok
f$xeeg() { :; } (simple expansion) ok ok
$x() { :; } (bare expansion name) syntax error ok
name() { :; } (plain) ok ok

An unquoted $(...) anywhere inside the function-name word trips the rejection; quoting the command substitution makes rubash accept the same word.

Real-world evidence (ecosystem harvest)

gingerpaledale/zZshFramework/src/files.sh, line 5 (harvest 2026-10-04):

fileRemoveWithOverwrite-dirOrFile$(useWithCaution)__hsl() {
  • WSL GNU Bash 5.3.0 bash -n: rc=0 on the whole file (recorded oracle, harvest 2026-10-04/05)
  • Git Bash 5.2 grammar: rc=0 (non-authoritative corroboration)
  • rubash master a157656 rubash -n: rc=2, syntax error near unexpected token '('
  • rubash's own runtime sources the file (ConPTY run reaches the prompt and defines the function) — only the -n parse path rejects.

GNU C source anchor (vendored bash.git @b4608166, Bash-5.3 patch 15)

  • parse.y:1054 function_def: WORD '(' ')' newline_list function_body — the rule requires a WORD; a word containing an unquoted $(...) is still a single WORD token (the lexer folds $(...) into the word via parse_comsub, cf. the $( branch at parse.y:5513-5532 which appends the substitution text into the current token), so f$()g is a valid WORD in function_def position.

Classification

Parser divergence (function-definition name word admission). Note the runtime/parser split inside rubash itself: rubash -n rejects what rubash's own executor accepts — the fix belongs in the function-definition admission of the parse path used by -n.

Activity

  1. added
    bug
    gnu-baseline
    P3-low
    on Oct 9, 2026
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

    P3-lowbuggnu-baseline

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions