Hello Zsh Development Team,
I'm reporting a bug in zsh's handling of escaped backslashes within double-quoted strings. When \\b appears in a double-quoted string, zsh incorrectly processes it as a backspace control character, even though the backslash has been properly escaped.
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)
The sequence \\b should produce:
\\ → literal \ (escaped backslash)b → literal b\b (two literal characters)Instead, zsh appears to:
\\ → literal \ ✓\ combined with b as \b → backspace control character (0x08) ✗I've confirmed that both echo and printf exhibit 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.
The bug only affects certain characters:
| Input | Expected | Actual |
|---|---|---|
\\s |
\s |
\s ✓ |
\\x |
\x |
hex escape prefix ✗ |
\\b |
\b |
backspace control char ✗ |
\\t |
\t |
inserts a tab character✗ |
\\n |
\n |
inserts a new line ✗ |
The correctness of escaping depends on which character follows the escaped backslash, which violates fundamental escaping semantics.
The same commands work correctly in bash:
# In bash:
echo "\`\\blog\\\`"
# Output: `\blog\` ✓ (correct)
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.
This bug affects:
\b, \a, \f, etc.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:
\\slog vs \\blog comparison showing the inconsistencyecho and printf producing 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
Attachment:
Screenshot from 2025-11-26 12-38-08.png
Description: PNG image