Skip to content

[bug] Single-quoted ${var/pat/repl} inside $() command substitution is expanded (GNU: literal) - OMB iterate theme loses all prompt segments #416

Closed

Description

@caomengxuan666

Found by wt53/themesweep (2026-10-03) running the full oh-my-bash per-theme INTERACTIVE load sweep (corpus abf8461, WSL GNU 5.3.0 oracle).

Minimal reproducer (script file, both shells)

out2=$(printf '%s\n' "PROMPTSEG> exit" | sed -n '${s/^\(.*\)exit$/\1/p;}')
printf 'PIPE_LITERAL=[%s]\n' "$out2"
  • GNU bash 5.3.0: PIPE_LITERAL=[PROMPTSEG> ]
  • rubash 1.3.0 (release, master a226108): PIPE_LITERAL=[]

The single-quoted sed program ${s/.../.../p;} must reach sed verbatim; under rubash it is expanded as shell parameter substitution (variable s unset -> empty), so sed runs with an empty program. The same text at top level (not inside $( )) and via "${1}" indirection is preserved - the leak is specific to the single-quoted ${...} form inside a command substitution in a script file.

GNU spec: single-quoted text is never subject to expansion - parse.y:5305 read_token_word() single-quote branch collects the body literally; command substitution bodies are re-parsed as fresh input (subst.c:7143 command_substitute) with the same quoting rules. Rust owner to map on the comsub body split path.

Impact

oh-my-bash iterate theme (themes/iterate/iterate.theme.sh:38-47) measures its prompt with a nested $(PS1="..." "$BASH" --norc -i | sed -n '${s/^\(.*\)exit$/\1/p;}'); the leak makes every measurement empty, the theme's cache check blanks new_PS1, and the stored PS1 loses ALL dynamic segments (GNU shows the full two-line prompt, rubash shows only the arrow). Confirmed on the interactive load sweep: rubash PS1 = \[\e[0;32m\]→\[\e[39m\] , GNU = full ± \w |master ?:1 ✗| \n→ prompt.

Raw artifacts

  • Probe: target/issue-suites/results/themesweep/probes/quote-leak-bisect.sh (5-case bisection)
  • Sweep outputs: target/issue-suites/results/themesweep/omb-a/{out-rb2,out-gnu}/iterate.out
  • Verdict matrix: target/issue-suites/results/themesweep/omb-a/themes-A2.json

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