Hello Zsh Development Team,
I'm reporting a bug in zsh's handling of escaped backslashes within double-quoted strings. When
\\bappears in a double-quoted string, zsh incorrectly processes it as a backspace control character, even though the backslash has been properly escaped.Environment
- Zsh version: 5.9
- Terminal: Ghostty
- OS: Ubuntu 24.04
- Comparison: This bug does NOT occur in bash - bash handles the same input correctly
Minimal Reproduction
The bug is clearly demonstrated by comparing two nearly identical commands:
echo "\`\\slog\\\`"Expected output: `
\slog\`
Actual output: `\slog\`✓ (works correctly)echo"\`\\blog\\\`"Expected output: `
\blog\`
Actual output:log\`✗ (incorrect - backspace eats preceding characters)Analysis
The sequence
\\bshould produce:
\\→ literal\(escaped backslash)b→ literalb- Final result:
\b(two literal characters)Instead, zsh appears to:
- Process
\\→ literal\✓- Reprocess the literal
\combined withbas\b→ backspace control character (0x08) ✗- The backspace then erases preceding text
This is a Parser Bug, Not a Builtin Issue
I've confirmed that both
echoandprintfexhibit identical behavior, proving this occurs during quote parsing before command execution:printf "xyz \`\\blog\\\` \\n" # Output: xyz log\` echo printf "xyz \`\\slog\\\` \\n" # Output: xyz `\slog\`Both produce the same incorrect output, confirming the bug is in zsh's double-quote parser.
Inconsistent Behavior
The bug only affects certain characters:
Input Expected Actual \\s\s\s✓\\x\xhex escape prefix ✗ \\b\bbackspace control char ✗ \\t\tinserts a tab character✗ \\n\ninserts a new line ✗ The correctness of escaping depends on which character follows the escaped backslash, which violates fundamental escaping semantics.
Bash Comparison
The same commands work correctly in bash:
# In bash: echo "\`\\blog\\\`" # Output: `\blog\` ✓ (correct)Expected Behavior
Once a backslash has been escaped with
\\, it should become literal and must not participate in further escape recognition. This is standard escaping behavior across all programming languages and shells.Affected Use Cases
This bug affects:
- Scripts outputting literal paths or strings containing
\b,\a,\f, etc.- Data serialization and logging
- Any code dynamically constructing strings with backslashes
- Cross-shell compatibility
Technical Description
The bug appears to be a double-processing issue where zsh's escape processor runs after escape consumption in double-quoted strings, allowing already-escaped backslashes to trigger control escapes on a second pass when followed by specific characters that form C-style escape sequences.
I've attached screenshots demonstrating:
- The
\\slogvs\\blogcomparison showing the inconsistency- Both
echoandprintfproducing identical incorrect output, proving this is a parser issuePlease let me know if you need any additional information or test cases.
Thank you for maintaining zsh!
Best regards, Jelius