Skip to content

[bug] Backslash inside a single-quoted alias body is dropped from the stored alias value (alias path='echo -e ${PATH//:/\n}' stores 'n') #301

Closed

Description

@caomengxuan666

Found by the ecosweep lane (wt10/ecosweep, 2026-09-28) running the mathiasbynens/dotfiles bash chain.

Minimal reproducer (script file, both shells)

alias path='echo -e ${PATH//:/\n}'
alias | grep 'alias path='
  • GNU bash 5.3.0: alias path='echo -e ${PATH//:/\n}' — the single-quoted body keeps the
    backslash verbatim.
  • rubash: alias path='echo -e ${PATH//:/n}' — the backslash is silently removed from
    the stored alias value.

Effect at use time: path prints the whole $PATH as one line (no \n separators).

Real-world corpus

mathiasbynens/dotfiles .aliases:148 is exactly this shape
(alias path='echo -e ${PATH//:/\n}'; with the doubled backslash the stored rubash value
collapses to a bare n). Seen in the alias-table diff of the sourced-chain probe:

  • GNU: alias path='echo -e ${PATH//:/\n}'
  • rubash: alias path='echo -e ${PATH//:/n}'

Also visible: alias np='nano ~/Dropbox\ \(Personal\)/notes.txt' (escaped spaces inside
single quotes) — stored identically on both shells for THAT one, so the loss is specific to
\ before a regular character (n), not to the \( escaped-punctuation forms.

GNU C anchor

Alias values are ordinary words parsed by parse.y:5305 read_token_word(); inside single
quotes NO backslash processing happens at parse time (sh_syntaxtab / quoting state —
CBSDQUOTE applies to double quotes only), and alias.c add_alias() stores the token
bytes verbatim. The single-quoted body must reach the alias table byte-for-byte.

Distinct from #218 (unquoted assignment-RHS expansion collapsing \) — this one is a
plain single-quoted word with no expansions at all.

Artifacts

  • target/issue-suites/results/ecosweep/probes/b12-alias-bs.sh (+ .rb.out/.gnu.out)
  • target/issue-suites/results/ecosweep/probes/b04-alias-{rb,gnu}.txt — full alias-table diff of the mathiasbynens chain

Activity

  1. added
    bug
    gnu-baseline
    on Sep 28, 2026
  2. added a commit that references this issue on Sep 28, 2026
  3. caomengxuan666 commented on Sep 28, 2026

    @caomengxuan666
    MemberAuthor

    Fixed by wt11/almix (f9d9be44, master): the alias body was corrupted at the ARGV expansion layer — for assignment-shaped parameter words the lexer's quote stripping preserved bare backslashes in fully single-quoted spans, and the embedded walker's -folding arm then collapsed them. One invariant, two sites: fully-single-quoted assignment spans now map \ to the DATA_BACKSLASH carrier (protect_fully_single_quoted_assignment), and the quote-RHS branch converts any surviving bare \ (only possible as quoted-span data) to the carrier with conservative bail-outs. GNU anchors: parse.y:5419-5436 -> subst.c:11881-11932 expand_word_internal quote case -> add_quoted_string/quote_string (subst.c:4773) whole-span CTLESC protection; builtins/alias.def:113-139 stores the expansion result verbatim.

    Verification: mathiasbynens:148 original repro (storage + alias inspection + use + reparse) byte-identical to WSL GNU Bash 5.3.0; backtick family b1-b9; assignment-argv full shape matrix; alias-use probes via script files (not -c, matching GNU's whole-string preparse); 10 new regression tests; 503 lib / 27 regression / carrier golden green.

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

    buggnu-baseline

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions