Skip to content

${x//\\\\/@} replaces each backslash, not each pair #3963

Closed

Description

@ShiomiHC
x='a\\b\c'
printf '%q\n' "${x//\\\\/@}"

niu: a@@b@c
Git Bash 5.3.15: a@b\\c

niubash 1.5.0 (rubash 29bbf52); also on master fb025fc. Windows 11.

Found while trying niu as the shell for Claude Code's Bash tool; the issue was drafted with Claude and the reproductions were run on the versions above.

Activity

  1. ShiomiHC commented on Nov 20, 2026

    @ShiomiHC
    Author

    A related case with a single-quoted pattern:

    a='x\/y'
    printf '%q\n' "${a//'\/'/\/}"

    niu: x\\/y, Git Bash 5.3.15: x/y. "${a//"\\/"/\/}" gives x/y in both.

  2. caomengxuan666 commented on Nov 20, 2026

    @caomengxuan666
    Member

    CAPTAIN-VERIFY (2026-11-20): confirmed against the GNU bash 5.3.20 oracle. Master reproduced the report exactly (a@@b@c); GNU gives a@b\c. Root cause: the pattern decoder collapses a source \\ pair to one literal-backslash marker, but the literal (non-glob) fast path folded adjacent markers a second time, halving the pattern — so each single backslash matched instead of each pair. The same folding was reused by the glob path's tail computation.

    Fixed in #3974 (strict 1:1 marker conversion, pair-folding pass deleted, unit regression added): 16/16 probes across the adjacent forms now match the oracle byte for byte. Closing as completed. Thank you for the precise report — the repro pinned the face immediately.

  3. added
    gnu-baseline
    on Nov 20, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

gnu-baseline

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions