Skip to content

fix(echo): accept -e, -E and combined -neE option words - #211

Merged
ferdingler merged 2 commits into
strands-agents:mainfrom
ferdingler:fix/echo-e-flag
Nov 12, 2026
Merged

ferdingler merged 2 commits into
strands-agents:mainfrom
ferdingler:fix/echo-e-flag

Conversation

@ferdingler

@ferdingler ferdingler commented Nov 6, 2026 •

Copy link
Copy Markdown
Collaborator

Description

echo only understood a single leading -n, so anything else got printed as text. For instance echo -e 'a\tb' printed -e a b, echo -ne x printed -ne x, and -E didn't stop escapes from expanding. Agents write echo -e all the time, so this kept leaking flags into their output.

Now echo reads leading -n, -e and -E the way bash does, including combined words like -ne and separate ones like -n -e, and the last of -e/-E wins. Words like -x, -nx or -- are still printed as text, same as bash. Plain echo with no flags still expands escapes like before; switching it to bash's no-expansion default would be a separate change.

I compared each case against bash. The new option tests fail on main and pass with the change, and the full Rust suite passes.

Related Issues

Part of #207

Documentation PR

N/A

Type of Change

Bug fix

Testing

How have you tested the change? Verify that the changes do not break functionality or introduce new warnings.

  • I ran the relevant test suites for the bindings I touched (cargo test --workspace --all-targets, pytest tests/python, npm test)
  • If I touched Rust, I ran cargo fmt and cargo clippy

Checklist

  • I have read the CONTRIBUTING document
  • I have reviewed and understand every line of code in this PR, including any generated by AI tools, and I can explain why it works
  • My change is focused and reasonably small; I have split unrelated work into separate PRs
  • I have added any necessary tests that prove my fix is effective or my feature works
  • I have updated the documentation accordingly
  • I have added an appropriate example to the documentation to outline the feature, or no new docs are needed
  • My changes generate no new warnings
  • Any dependent changes have been merged and published

By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.

@ferdingler
ferdingler marked this pull request as ready for review November 12, 2026 19:33
@ferdingler
ferdingler requested a review from a team as a code owner November 12, 2026 19:33
@ferdingler

Copy link
Copy Markdown
Collaborator Author

@strandly-the-agent Please review this PR

@strandly-the-agent strandly-the-agent left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Approve. The option parsing matches bash on every case I tried, and the new tests prove the fix: 14 of the 18 fail on main and pass here. Nothing in this PR is blocking.

Two non-blocking follow-ups:

  • Docs will go stale (harness-sdk). site/src/content/docs/user-guide/shell/commands.mdx says: "echo | Expands escapes by default; -e and -E are printed literally (escape expansion cannot be disabled)." After this merges, both halves are wrong. That file lives in another repo, so it needs a separate docs PR.
  • Question: -e is now honored, but expand_escapes (src/builtins/echo.rs:55) has no \x or \u (and no \e). So echo -e 'a\x41b' prints a\x41b; bash prints aAb. This was already true on main. printf::escape_all (src/builtins/printf.rs:360) already handles \x/\u. Could echo reuse it in a follow-up?
What I verified
  • Head 283b454. cargo test --test shell_integration: 1642 passed. cargo test --test differential: passed.
  • With src/builtins/echo.rs reverted to main and the PR's tests kept, 14/18 echo_opt_* tests fail and the differential test fails. The other 4 (-x, -nx, --, -) guard against regressions. Removing the known-difference marker from echo_e.sh is correct.
  • I compared 28 commands through bash -c and strands-shell -c (byte-level, od -c). 27 match, including: -ne, -eE, -E -e, -neEx, -enen, -e-n, '' -n x, x=-e; echo $x …, quoted "-n", -E with \c, -e with \0101, multi-byte args, pipes, and $(echo -ne k). The one mismatch is the \x case above.
  • Other call sites: command echo, builtin echo, /bin/echo, xargs echo -e, and find -exec echo -e all reach the builtin and match bash. src/commands/echo.rs is a lexopt-based echo that rejects -n/-e, but builtins are looked up first (src/exec.rs:3276, :3541), so none of these paths reach it.
  • Nit: the PR fixed the stale "echo -e is not supported" comment, but tests/shell_integration.rs:3969 still has the header // ── echo -e escape sequences above a printf test.

@ferdingler

Copy link
Copy Markdown
Collaborator Author

Thanks for checking the regressions against main. Agreed that the command table in harness-sdk needs a separate docs update; this PR changes option parsing and keeps the existing default escape behavior.

Sharing escape handling makes sense as a follow-up, with explicit echo/printf rules. I checked that echo -e '\101' stays literal while printf '%b' '\101' emits A, and echo already supports \a, \b, \f, and \v that printf's helper currently leaves literal. So reusing escape_all unchanged would alter existing behavior. A shared helper needs tests for those differences alongside \x/\u/\e. The old printf-test heading can go with that cleanup.

@ferdingler
ferdingler merged commit 7000b66 into strands-agents:main Nov 12, 2026
31 of 60 checks passed
@ferdingler
ferdingler deleted the fix/echo-e-flag branch November 12, 2026 23:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants