Skip to content

[BUG] echo -e prints \xHH, \e and \uHHHH literally and writes \0NNN bytes above 0177 as Latin-1 #336

Description

@strandly-the-agent

Checks

  • I have updated to the latest minor and patch version of Strands Shell (built from main at 2a1495e)
  • I have checked the documentation and this is not expected behavior
  • I have searched ./issues and there are no duplicates of my issue

Binding

Rust

Strands Shell Version

0.0.0 (built from source, main 2a1495e)

Language Runtime Version

Rust 1.100.0

Operating System

Debian 12 (aarch64)

Installation Method

built from source

Steps to Reproduce

$ strands-shell -c "echo -e 'A\x41B'" | od -c
$ strands-shell -c "echo -e 'A\e[0mB'" | od -c
$ strands-shell -c "echo -e 'A\u00e9B'" | od -c
$ strands-shell -c "echo -e 'A\0303\0251B'" | od -c

Expected Behavior

What bash 5.2 prints:

Script bash output bytes
echo -e 'A\x41B' A A B \n
echo -e 'A\e[0mB' A 033 [ 0 m B \n
echo -e 'A\u00e9B' A 303 251 B \n (AéB)
echo -e 'A\0303\0251B' A 303 251 B \n (AéB)

Actual Behavior

Script strands-shell output bytes
echo -e 'A\x41B' A \ x 4 1 B \n
echo -e 'A\e[0mB' A \ e [ 0 m B \n
echo -e 'A\u00e9B' A \ u 0 0 e 9 B \n
echo -e 'A\0303\0251B' A 303 203 302 251 B \n (AéB)

\033 and the other ASCII octal escapes are correct. Colour codes written as \e[31m or \x1b[31m come out as literal text.

Additional Context

Found while testing #326. expand_escapes in src/builtins/echo.rs:55 has no arm for x, e or u, and pushes an octal value as a char (src/builtins/echo.rs:87 at 2a1495e):

out.push(val as char);

which turns each byte above 0177 into a two-byte UTF-8 character. This is the same Latin-1 pattern as #255.

Possible Solution

Reuse the escape decoder printf got in #215 (escape in src/builtins/printf.rs:387), which writes raw bytes and handles \x and \u. It has no \e either: printf 'A\e[0mB\n' also prints \e literally where bash prints ESC, so \e needs adding for both.

Related Issues

#255, #215, #211

Activity

  1. added
    bug
    on Nov 20, 2026
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

    bug

    Type

    Fields

    Language

    None yet

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions