Skip to content

[bug] Parser over-strict: bare '!(*.mp3|*.wmv)' at command position (extglob OFF) rejected — GNU parses it as '!' + subshell and accepts (rc=0) #361

Closed

Description

@caomengxuan666

Found by ecosweep4 lane (wt22/nest22; ShellCheck unit-test corpus probe Parser_1985, bash -n parity vs WSL GNU Bash 5.3.0 script-file run; worktree base a522eb3, release build).

Reproducer

File containing exactly one line:

!(*.mp3|*.wmv)
  • rubash -n: line 1: syntax error near unexpected token '*.mp3' (rc=2)
  • GNU 5.3.0: rc=0 — with extglob OFF, !( is NOT an extglob starter; GNU lexes ! as the pipeline-negation reserved word and (*.mp3|*.wmv) as a subshell body, which is valid grammar (! (pipeline)).

GNU owner

The extglob admission in the lexer is gated on the live extended_glob variable (parse.y:5466 if (extended_glob) ... in the (-consumption path — the same anchor cited in rubash#332 for the inverse direction: there our gate stayed OPEN after shopt -u; here our gate appears to treat !( as extglob even when extglob was never enabled, so the word is parsed as a pattern and the | inside produces the *.mp3 syntax error).

Also worth checking the extglob-ON case for parity: GNU then lexes !(*.mp3|*.wmv) as an extglob WORD at command position — also accepted (rc=0); rubash should match in both states.

Probe

target/issue-suites/results/ecosweep4/sc/snips/Parser_1985.sh; matrix sc/{rub,gnu}.rc.txt line Parser_1985 (rub=2 gnu=0).

Classification: rubash-caused (lexer admission gate), over-strict direction. Family: #332 (gate tracking), #221/#222 (extglob-in-construct admission from the mvdan corpus).

Activity

  1. added
    bug
    on Sep 30, 2026
  2. added 2 commits that reference this issue on Sep 30, 2026
  3. caomengxuan666 commented on Sep 30, 2026

    @caomengxuan666
    MemberAuthor

    Fixed by wt22/p0fix (3ade4b2): the scanner routed !( unconditionally through extglob lexing. GNU with the gate OFF: the word scan stops at (, the bare ! goes through CHECK_FOR_RESERVED_WORD (parse.y:3168-3181) as BANG — !(.mp3|.wma) is negation of a subshell. Now command-position !( with extglob OFF yields Keyword !. Bonus finding recorded: GNU 5.3.0 runtime shopt -s extglob (same-line/other-line/-c) does NOT open the parse-time gate — only the startup -O extglob does — and rubash's existing gate tracking (#131/#332) already matches, all shapes byte-identical both shells. Full ShellCheck corpus 2164/2164 parity. extglob 16=16, glob 44=44. 6 regressions.

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

    bug

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions